Okay, I'm gonna dive in now with my 5 cents/pence/yen/lire/imperial credits
Here is your code:
Load image "Images\Goku Running1.png",1
Load image "Images\Goku Running2.png",2
do
Sprite 999, Xpos, Ypos, 1
`Moves Sprite Left.
If leftkey() = 1
Xpos = Xpos - 5
endif
`Moves Sprite Right.
If Rightkey() = 1
Xpos = Xpos - -5
endif
sync
loop
You're not actually telling it to do anything with your images. Below are some alterations based on the two strategies put forward:
Scenario 1 (Easiest) (What EricB was talking about)
remstart
1) Take "Goku Running1.png" and combine image with "Goku Running2.png" so that they are next to one another.
as EricB mentioned, they must be the same size. EG if "Goku Running1.png" is 64x64 then "Goku Running2.png"
must be 64x64. If they don't match, increase the actual canvas size (not scaling the image) on whichever is
smaller and make it tansparent (the canvas, not the image). Now you paste them side by side and save as
"GokuRunning.png"
2) Code time. I have altered your code and done my best not to modify too much. If you don't understand what
I've done or why please ASK, otherwise you won't get the hang of it.
remend
GokuRunning = 999
animationdelay = 50
CREATE ANIMATED SPRITE 999, "Images\GokuRunning.png", 2, 1, 999
do
Sprite GokuRunning, Xpos, Ypos, GokuRunning
PLAY SPRITE GokuRunning, 1, 2, animationdelay
`Moves Sprite Left.
If leftkey() = 1
DEC Xpos, 5
endif
`Moves Sprite Right.
If Rightkey() = 1
INC Xpos, 5
endif
sync
loop
`Dunno how accurate t3h codez is coz I can't test it, should work though.
Scenario 2 (Harder, more control) (What Hodgey was talking about)
remstart
1)You need not create a single image in this scenario as we will be using Hodgey's
method. Consequently, I take NO responsibility for this code as I've never done things
this way in DBPro before.
2)Don't discard this method just because it is harder. You have more control this way
and while it is not the best method for your scenario, it will serve you in complex
situations, perhaps regarding "paper-dolling" (http://en.wikipedia.org/wiki/Paper_doll)
your sprites, etc in your future games. It is also a good foundation to build understanding
of graphics, frames, timing, etc. on.
remend
GokuRunning1 = 998
GokuRunning2 = 999
GokuFrame = 998 `Your initial frame should be Goku standing, but in anycase.
animationdelay = 50
GokuTime = 0
Load image "Images\Goku Running1.png", GokuRunning1
Load image "Images\Goku Running2.png", GokuRunning2
`Initialise your sprite first.
Sprite Goku, startposX, startposy, GokuFrame
do
Sprite Goku, Xpos, Ypos, GokuFrame
`Moves Sprite Left.
If leftkey() = 1
IF TIMER() - GokuTime > animationdelay
INC GokuFrame, 1
`If Goku's frame is greater than the LAST FRAME in the running range, reset frame
`to the first in the running range.
IF GokuFrame > 999 THEN GokuFrame = 998
`Now we reset the timer
GokuTime = TIMER()
ENDIF
DEC Xpos, 5
endif
`Moves Sprite Right.
If Rightkey() = 1
IF TIMER() - GokuTime > animationdelay
INC GokuFrame, 1
`If Goku's frame is greater than the LAST FRAME in the running range, reset frame
`to the first in the running range.
IF GokuFrame > 999 THEN GokuFrame = 998
`Now we reset the timer
GokuTime = TIMER()
ENDIF
INC Xpos, 5
endif
sync
loop
`Dunno how accurate t3h codez is coz I can't test it, should work though.
In both examples, there is one major flaw but I ignored it in the coding since this topic's about animating sprites. I'd still better point it out. You need to either have different frames facing left/right OR you need to flip your sprites horizontally when changing directions (this may cause some minor accuracy problems with positioning based on how well-centered your images were on your canvas when you made them). Anyway, hope this helps break things down a little better.
Btw, you should place code in snippets like so...
[ code]
your codez
[ /code]
...but without the space.
Good luck and happy game making!