Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Working with sprites

Author
Message
Garfield1983
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location:
Posted: 5th Jan 2003 23:32
I've taken the advice of other forum peeps and am staring small, i'm making a little 2D space shooter=)

I've been pointed in the direction of sprites and i now know how to animate them but how do move them? For example, i want my little animated spaceship to move when i press the arrow keys.

Can anyone tell me some commands for using sprites? All i've found in the DB help files is about making them and so far on DBHeaven i've just learned how to animate them.

Can anyone help? cheers

~Gar~
Xsniper
21
Years of Service
User Offline
Joined: 29th Dec 2002
Location:
Posted: 6th Jan 2003 00:51
There are two ways that I can immediately think of to move a sprite. The first would be using the "move sprite" and the "rotate sprite" command in conjunction with eachother. "move sprite" gives the sprite a velocity and pushes the sprite constantly in the direction it is facing so to speak. "rotate sprite" will change the direction it is facing thus making it where you can do turns or other things with the sprite.

The other way to move the sprite is a more direct way and is good if you don't want something to be constantly moving. Simply use the "sprite" command but with new x and y coordinates and it will move the sprite to that position. So you can put this in a loop or attach it to the arrow keys etc. Hope this helps.

Garfield1983
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location:
Posted: 6th Jan 2003 02:41
I couldn't find anything on the Move or Rotate Sprite commands and the 2nd method isn't really what i want because the sprite 'jumps' to a specified area whereas i want to see it moving, sorry.

Would you able to give me the syntax for the move and rotate sprite commands? Thanks
Xsniper
21
Years of Service
User Offline
Joined: 29th Dec 2002
Location:
Posted: 6th Jan 2003 04:18
Are you using DB or DBP? If you are using DBP then the commands are in the commands->sprites-> section of the help file. But I'll post the syntax here anyway. Also if you do the "sprite" command correctly it can be seemless movement, not "jumpy".

move sprite syntax:
MOVE SPRITE Sprite Number, Velocity

rotate sprite syntax:
ROTATE SPRITE Sprite Number, Angle

Here is a little snippet from my Breakout Clone that I made in DBP that uses the "sprite" command to move the paddle left and right on the screen.

rem Paddle Control
_control_paddle:
rem Left and Right keys move paddle
if leftkey() then paddleXleft = 10
if rightkey() then paddleXright = 10
rem Up key detaches ball
if upkey() then attached = 0
return

rem Update Paddle
_update_paddle:
rem Hopefully smoother paddle animation
if paddleXleft > 0
paddleX = paddleX - 3
rem Stop at left screen boundary
if paddleX < leftbound then paddleX = 0
cls
sprite paddleSnum, paddleX, paddleY, paddleInum
rem Move ball with paddle if its currently attached
if attached = 1
ballX = paddleX + 45
sprite ballSnum, ballX, ballY, ballInum
endif
dec paddleXleft
endif
if paddleXright > 0
paddleX = paddleX + 3
rem Stop at right screen boundary
if paddleX > rightbound then paddleX = rightbound
cls
sprite paddleSnum, paddleX, paddleY, paddleInum
rem Move ball with paddle if its currently attached
if attached = 1
ballX = paddleX + 45
sprite ballSnum, ballX, ballY, ballInum
endif
dec paddleXright
endif
return

Hope this helps.

Garfield1983
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location:
Posted: 6th Jan 2003 04:24
Thanks XSniper, your patience is much appreciated!=)

I'm using DB, does that mean what u just said doesn't apply? I'l try it anyway.

Thanks again!=)
Xsniper
21
Years of Service
User Offline
Joined: 29th Dec 2002
Location:
Posted: 6th Jan 2003 06:03
I'm not sure if it will work in DB or not because I've never really used it. Just bought DBP a few weeks ago. I hope it works out for you though .

cybersamurai
21
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 6th Jan 2003 06:25


that also works

Rusty Gears
cybersamurai
21
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 6th Jan 2003 06:26


this is the correct code, mad a simple mistake with the last

Rusty Gears
Xsniper
21
Years of Service
User Offline
Joined: 29th Dec 2002
Location:
Posted: 6th Jan 2003 08:20
Cyber, thats the way I did it originally but I found it was much smoother to have it move 10 or more pixels at a time than just one at a time.

Login to post a reply

Server time is: 2024-11-23 19:30:06
Your offset time is: 2024-11-23 19:30:06