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.

2D All the way! / Sprite movement. help

Author
Message
Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 31st May 2009 19:30
I need help to get my sprites to move with key presses. I have a sprite sheet with all my sprites on it, but need to draw the sprite in turn to get the movement. I need it to get right, left and jump.

Here's is some code i already have.



At the moment it just displays the 4 running sprites, but i need to get it to display just the first and then in others in sequence when i press the right key. I know i might be being a little vague but any help will be appreciated.

If you need any more info let me know.

And one final note im using DBC.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 31st May 2009 22:31 Edited at: 31st May 2009 22:56
To do multiple images with a single sprite you use a variable for the image number. When you go a different direction change the variable to the image number you want it to be. The variable can also be used to animate the character instead of just having one single image for going up, down, left, and right.

The following code won't work unless you add code to grab the other 3 images from your sprite sheet and make it a DO/LOOP (instead of just running through once and ending).


Can you upload the sprite sheet your using? I'm a fan of anything MegaMan.

Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 31st May 2009 23:19
Yea sure here's the sprite sheet:

Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Jun 2009 01:16
Cool thanks.

Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Jun 2009 02:58 Edited at: 1st Jun 2009 02:59
Since you were so kind uploading that sprite sheet here's a gift that will work in Classic.



Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 1st Jun 2009 17:32
Thanks mate that works great.

Do you know how i can make the sprite jump though instead of going up?
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Jun 2009 00:00 Edited at: 6th Jun 2009 00:03
Quote: "Thanks mate that works great."


Np.

Quote: "Do you know how i can make the sprite jump though instead of going up? "


Yeah you can make a variable to track the state of the jump. Everything from not jumping, jumping, and falling. I hope this doesn't insult you but when not jumping the current y coordinate stays the same. When jumping the y coordinate goes down (to go up the screen). And when falling the y coordinate goes up (to go down the screen).

Grab the image for jumping from the sprite sheet and do the following steps.

Initial jump steps (when hitting the jump key):

1. Make a variable to store the old sprite image with SPRITE IMAGE(spritenumber) so you don't miss a beat when jumping
2. Set the current image to the jump image number and make Jump=1
3. Make a variable to store the old y coordinate (to know where to stop the falling)
4. Make a variable to store the top of the jump (how high you want Protoman to jump)

Falling steps:

5. Check if Protoman is falling (Jump=2)
6. If yes then increase y coordinate
7. If current y coordinate is the same as the old y coordinate (set in step 3) make Jump=0 and reset the current image to the old image (set in step 1)

Jumping steps:

8. Check if Protoman is jumping (Jump=1)
9. If yes then decrease y coordinate
10. Check if current y coordinate is the same as the top of the jump (set in step 4) and make Jump=2

Additional step:

11. Add if Jump=0 to any image changing on left and right running (so it doesn't show him running while jumping)

Every jump also needs its own timer so you can change how far the jump will go (if running left or right). Experiment a bit with that and let me know if you have trouble.

Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 8th Jun 2009 19:39
I found this in the codebase for jumping



When i try and run this in my game it says 'Program has run into function declaration'. Do you know why?
vidmouse
14
Years of Service
User Offline
Joined: 28th Apr 2009
Location:
Posted: 10th Jun 2009 04:10
Just a guess...



as the declaration is the culprit...
this looks more like a function call statement

What does it look like when you call the function
in the main program?

Vidmouse's Software: http://www.freewebs.com/vidmouse/software.htm
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Jun 2009 11:06
Woah that's weird. To me this message showed me as the last poster but here's two messages I didn't see. Looks like the forum is up to it's old tricks. Sorry I didn't see your message sooner Corbula.

There's actually two problems. One because there's no END before hitting "function player_jump(7,10,10#)". That is the actual function not a call to it. You always need to have an END statement before it reaches any functions otherwise you'll get an error. And the "(7,10,10#)" looks as Vidmouse says a call to it. I think the poster of that code was still confused just how to make functions. There's also something in the math that causes an error with my compiler... it won't even try to run it.

It's been a while since you posted last. Is this still a problem for you or did you solve it?

Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 18th Jun 2009 14:44
Sorry ive not posted for a while.

I think i made the mistake of taking that from the codebase whithout looking at what it was for. I think it was for darkbasic pro.


But no i haven't got the jumping to work properly yet. Also ive got code for a scrolling background, that when on its own works fine. but placing it in my game it tells me either the image is to big or to small.
Bankzy10
15
Years of Service
User Offline
Joined: 29th Jan 2009
Location: Planet DarkBasic - Learning the tricks
Posted: 18th Jun 2009 20:49
Here is some code for a side scrolling that comes in from the right if this helps?



I hope this has helped you and keep us updated if you have any more problems.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2009 02:35
Quote: "I think i made the mistake of taking that from the codebase whithout looking at what it was for. I think it was for darkbasic pro."


I tried it in Pro and it just gave me errors. :-(

Quote: "But no i haven't got the jumping to work properly yet."


That's ok. The following code is what I was talking about. It doesn't have any fancy math so once it hits the ceiling it immediately goes down.



Corbula
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 22nd Jun 2009 13:59
Ok that works great and it all works (as far as i know). Also i was looking at the other thread about the scrolling background and decided to use it myself.

It works fine but instead of continuously moving the background it needs to move when the character sprite gets to about the middle of the screen then scroll and stop when the character stops.

Do you know how i can do this?

Login to post a reply

Server time is: 2024-04-27 04:35:24
Your offset time is: 2024-04-27 04:35:24