|
Post by cvirus on Aug 11, 2011 10:09:25 GMT -5
Hello everybody, i´m new to game programming an BAsic4gl to and i start to develop a simple game like those retro ones, but like i start i suddenly i encounter some barriers, here is my code and a screenshot of what i want to do. dim texture, sprite, backgroundImage, bgsprite dim sp1x, sp1y
backgroundImage = LoadTexture("fundo.bmp") bgsprite = NewSprite(backgroundImage) SprSetPos(320,240) SprSetSize(640,480) SprSetZOrder(2) texture = LoadTex("nave.png") sprite = NewSprite (texture) SprSetPos (100, 100) SprSetZOrder(1)
sp1x = 320 sp1y = 240
while true BindSprite(sprite) SprSetPos(sp1x,sp1y) if ScanKeyDown(VK_UP) then sp1y = sp1y-3 end if if ScanKeyDown(VK_DOWN) then sp1y=sp1y+3 end if if ScanKeyDown(VK_LEFT) then sp1x = sp1x-3 end if if ScanKeyDown(VK_RIGHT) then sp1x=sp1x+3 end if WaitTimer(20) AnimateSprites () wend My primary gold was to put a spinning background and some enemies moving in direction of the ship, any help is appreciated.
|
|
|
Post by matthew on Aug 11, 2011 16:44:52 GMT -5
I've altered your program & added a spinning background. If you want to add bullets & enemies you might want to take a look at this thread that Tom posted in. dim texture, sprite, backgroundImage, bgsprite dim sp1x, sp1y
backgroundImage = LoadTexture(".\Data\Star.bmp") bgsprite = NewSprite(backgroundImage) BindSprite(bgsprite) SprSetPos(320,240) SprSetSize(512, 512) SprSetZOrder(2)
texture = LoadTex(".\Data\F117.png") sprite = NewSprite(texture) BindSprite(sprite) ' SprSetPos (100, 100) SprSetZOrder(1)
sp1x = 320 sp1y = 240
while true BindSprite(bgsprite) SprSetAngle(SprAngle()+0.4) BindSprite(sprite) SprSetPos(sp1x,sp1y) if ScanKeyDown(VK_UP) then sp1y = sp1y-3 end if if ScanKeyDown(VK_DOWN) then sp1y=sp1y+3 end if if ScanKeyDown(VK_LEFT) then sp1x = sp1x-3 end if if ScanKeyDown(VK_RIGHT) then sp1x=sp1x+3 end if WaitTimer(20) ' SwapBuffers() AnimateSprites () wend
|
|
|
Post by cvirus on Aug 12, 2011 6:12:18 GMT -5
Thank you matthew, nice screenshoot, in my computer with win 7 32 bits when i run the i get a fullscreen with a 640 by 480 window, how can i get only my window with the size i want?
Thank you very much you help me alot.
|
|
|
Post by cvirus on Aug 12, 2011 6:42:18 GMT -5
Solved the window question, Thank you, just went to options an unchecked the full screen part. Thank you Why you put BindSprite(bgsprite) when you load a sprite and again in the while true loop? And is it possible to put the background scrolling instead of spinning?
|
|
|
Post by matthew on Aug 12, 2011 7:16:37 GMT -5
Whenever you want to perform operations on a sprite you need to tell Basic4GL which sprite you're using, which is what BindSprite does. You should take a look at the Sprite Library Guide here. If you want a scrolling background instead of a rotating one, take a look in your Basic4GL Programs folder for CavernDemo.gb.
|
|
|
Post by cvirus on Aug 12, 2011 9:12:23 GMT -5
Well i was reading about scrolling but seems a little hard to understand for a noob like me, but it have to do with something like this. while SyncTimer(10) SprCameraSetPos (SprCameraPos() + vec2 (2,15)) wend DrawText() and this SprSetParallax(true) I put this i my code but no luck, maybe i must do something different. . This is tough.
|
|
|
Post by PeterMaria on Aug 12, 2011 9:33:11 GMT -5
Hi cvirus,
CoolBasic forum gave you no propper answer for your problem? there is nobody in finland who can help you?
|
|
|
Post by matthew on Aug 12, 2011 10:08:42 GMT -5
Don't worry about SprSetParallax, you only need that if you're using different layers for your background. The following example uses only one layer & scrolls it from left to right, it's based on one in the Sprite Library Guide. If there's anything you don't understand, post your questions. Hi Peter I'm going to check out CoolBasic it sounds interesting. ' Replace black with transparent pixels SetTexTransparentCol(0, 0, 0)
' Load textures dim textures(TexStripFrames("data\spacetiles.png") - 1) = LoadTexStrip("data\spacetiles.png")
' Build tile map data 0, 0, 0, 1, 0 data 0, 1, 5, 0, 2 data 2, 3, 0, 0, 4 data 0, 0, 1, 2, 0 data 1, 4, 3, 0, 0 dim tiles(4)(4), x, y for y = 0 to 4 for x = 0 to 4 read tiles(x)(y) next next
' Create tile map sprite dim tile = NewTileMap(textures) SprSetSolid(false) SprSetTiles(tiles)
' Animate over a blue background glClearColor(0, .1, .3, 1) while true ' Scroll from left to right SprSetPos(SprPos() + vec2(-1, 0)) wend
|
|
|
Post by cvirus on Aug 12, 2011 14:28:25 GMT -5
Hi cvirus, CoolBasic forum gave you no propper answer for your problem? there is nobody in finland who can help you? Hello peterpan, yes they did, but the language is different and i like Basic4gl , and want to try out. matthew once more thank you for the fast reply, if i have more questions i will post it.
|
|
|
Post by cvirus on Aug 15, 2011 14:47:35 GMT -5
well here is the code so far, the main difference is the while true, the next thing to figure out is the part of making the 640x480 background not ending, this is, like a endless background.
dim texture, sprite, backgroundImage, bgsprite dim sp1x, sp1y
backgroundImage = LoadTexture("fundo.bmp") bgsprite = NewSprite(backgroundImage) BindSprite(bgsprite) SprSetPos(320,240) SprSetSize(640,640) SprSetZOrder(2) texture = LoadTex("nave.png") sprite = NewSprite (texture) BindSprite(sprite) SprSetPos (100, 100) SprSetZOrder(1)
sp1x = 320 sp1y = 240
while true BindSprite(bgsprite) while true SprSetPos(SprPos() + vec2(-1, 0)) wend BindSprite(sprite) SprSetPos(sp1x,sp1y) if ScanKeyDown(VK_UP) then sp1y = sp1y-3 end if if ScanKeyDown(VK_DOWN) then sp1y=sp1y+3 end if if ScanKeyDown(VK_LEFT) then sp1x = sp1x-3 end if if ScanKeyDown(VK_RIGHT) then sp1x=sp1x+3 end if WaitTimer(20) AnimateSprites () wend
|
|
|
Post by matthew on Aug 16, 2011 5:47:20 GMT -5
I've made some changes, like there's no need to use AnimateSprites because you aren't animating anything. Just use DrawText instead. dim texture, sprite, backgroundImage, bgsprite dim sp1x, sp1y
backgroundImage = LoadTexture(".\Data\Star.bmp") bgsprite = NewSprite(backgroundImage) BindSprite(bgsprite) SprSetPos(320,240) SprSetSize(640,640) SprSetZOrder(2) texture = LoadTex(".\Data\F117.png") sprite = NewSprite (texture) BindSprite(sprite) SprSetPos (100, 100) SprSetZOrder(1)
sp1x = 320 sp1y = 240
while true while SyncTimer (10) BindSprite(sprite) SprSetPos(sp1x,sp1y) if ScanKeyDown(VK_UP) then sp1y = sp1y-3 end if if ScanKeyDown(VK_DOWN) then sp1y=sp1y+3 end if if ScanKeyDown(VK_LEFT) then sp1x = sp1x-3 end if if ScanKeyDown(VK_RIGHT) then sp1x=sp1x+3 end if wend
DrawText() wend
|
|
|
Post by cvirus on Aug 16, 2011 6:45:36 GMT -5
Thank you for the explain, but i must put this to scroll the background
BindSprite(bgsprite) while true SprSetPos(SprPos() + vec2(-1, 0)) wend
The next step is an endless background ex:
dim move=0
setsprpos(0-move,0) setsprpos(move-640,0)
move=move+1
if move>=640 then
move=0
end if
is this possible.
|
|
|
Post by matthew on Aug 16, 2011 7:09:40 GMT -5
Try the following. dim texture, sprite, backgroundImage, bgsprite dim sp1x, sp1y
backgroundImage = LoadTexture(".\Data\Star.bmp") bgsprite = NewSprite(backgroundImage) BindSprite(bgsprite) SprSetPos(320,240) SprSetSize(640,640) SprSetZOrder(2) texture = LoadTex(".\Data\F117.png") sprite = NewSprite (texture) BindSprite(sprite) SprSetPos (100, 100) SprSetZOrder(1)
sp1x = 320 sp1y = 240
while true
BindSprite(bgsprite) SprSetPos(SprPos() + vec2(-1, 0)) if SprX() = -320 then SprSetX(960) endif
while SyncTimer (10) BindSprite(sprite) SprSetPos(sp1x,sp1y) if ScanKeyDown(VK_UP) then sp1y = sp1y-3 end if if ScanKeyDown(VK_DOWN) then sp1y=sp1y+3 end if if ScanKeyDown(VK_LEFT) then sp1x = sp1x-3 end if if ScanKeyDown(VK_RIGHT) then sp1x=sp1x+3 end if wend
DrawText() wend
|
|
|
Post by cvirus on Aug 16, 2011 7:52:19 GMT -5
Now is working good except the gap between the end of the background and the beginning, i tried to change the values in the sprSetPos() and in the -320 but nothing worked
if SprX() =-320 then <-- this is the original x pos of the sprite and if it reaches less 320 the put x position of the sprite 960 right? SprSetX(960) <--why 960? end if
|
|
|
Post by matthew on Aug 16, 2011 9:32:09 GMT -5
Okay, I've solved the scrolling background problem by attaching two sprites side-by-side. Download & run this example to see it in action. There's another way of scrolling a background using OpenGL which can be seen here or you could just use tilemaps (recommended) which are designed to be repeated.
|
|