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 / moving sprites

Author
Message
mo2970
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 11th Jul 2006 22:00
i am having trouble moving sprites, i need the comp to move a sprite slowly so the player can go around it, i am workin on a 2d game for a start, and it is lookin down on the main charecter as they collect power ups to fight through the enemies. this is the code and i need another way of moving the sprite

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 11th Jul 2006 23:23
I haven't tested this, but it should work better than what you have posted.

The problem was that it would go to play level and then be in a do-loop. It never leaves this loop, so it never returns, and therefore never goes to the _movin label.



D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 11th Jul 2006 23:45 Edited at: 12th Jul 2006 00:22
You will have to place all of the game action code within one loop.
I also suggest using sync within the game loop. This will keep your
game play consistant on any PC. Don't use the WAIT command to set a
delay inside of the main loop. It will cause the entire game to hault
temporarily for one action. You might want to look into using the
TIMER() function for that.

My mods (I did not test the code, but it should work):


All variables for sprite #3 are set up here as an example.
You can change the axis and speed of movement as you like.
mo2970
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 12th Jul 2006 03:11
D ogre that almost works but it is moving left-right and i want it to move up-down then back up. i have thecode u suggested whichs looks like this

and i cant figure out which part changes what, so that i could adjust it to what i want
mo2970
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 12th Jul 2006 06:33
whoops i forgot to mention i am using DB Pro!
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 12th Jul 2006 06:39
(untested)

Up and down is on the y axis just as it would be on a graph. That means you would change this-

sprite 3,sprite x(3)+move,sprite y(3),3

to this-

sprite 3,sprite x(3),sprite y(3)+move,3

or if that is going the wrong way it might be this

sprite 3,sprite x(3),sprite y(3)-move,3

mo2970
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 12th Jul 2006 06:45
oh i see thank you so much.
mo2970
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 12th Jul 2006 07:01
ok that seems to work, but how to i make it go so far then turn around and go back, on a loop?
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 13th Jul 2006 01:30
Try changing these two lines:


The limit was set in my example code to 40 pixels. Just change it
to whatever works for you. If the code works as you say it does,
the first line above will reverse the direction of the sprite when
it exceeds 40 pixels, and the second line will reverse direction of
the sprite when it is less then 0 pixels from the starting position.

Keep this line as:


The variable move will be calculated like this:

if move is greater than forty, then move = 41 + (-1) = 40
if move is less than zero, then move = -1 + 1 = 0

and so on...

Remember, addition can be done with positive or negative values.

Move is then added to the current sprite position on the Y axis.

Login to post a reply

Server time is: 2024-11-26 15:31:29
Your offset time is: 2024-11-26 15:31:29