I'm having troubles using the Animated sprite command. When ever I assign frames to a keystroke it randomly plays other frames outside of its range.
the code:
sync on
sync rate 30
set image colorkey 255,0,255
create animated sprite 1,"MainChar.bmp",3,4,1
xpos#=100
ypos#=100
do
cls rgb(200,200,200)
paste sprite 1,xpos#,ypos#
if keystate(17)=1 then play sprite 1,10,12,100: dec ypos#, 2
if keystate(30)=1 then play sprite 1,7,9,100:dec xpos#,2
if keystate(32)=1 then play sprite 1,4,6,100:inc xpos#,2
if keystate(31)=1 then play sprite 1,1,3,100:inc ypos#,2
sync
loop
there is a zip attachment that has the code as well as the media and a compiled version as well.
If you use the WASD keys the sprite will move around and the animation will play. However if you change direction before the animation loop is allowed to finish (I assume) then it will mess up and skip to a random frame. What's the correct way of using this command?
EDIT
Google forum search for "Sprite Movement" revealed a topic in the 2D board that had the code outline for an animated sprite (I thought that forum was for pictures/textures etc)
Updated, now working:
sync on
sync rate 30
set image colorkey 255,0,255
create animated sprite 1,"MainChar.bmp",3,4,1
xpos#=100
ypos#=100
do
cls `rgb(200,200,200)
paste sprite 1,xpos#,ypos#
if rightkey()=1
if cdir=1
play sprite 1,4,6,100
if SPRITE FRAME(1)>6 then SET SPRITE FRAME 1,4
else
SET SPRITE FRAME 1,4
cdir=1
endif
inc xpos#,1.5
endif
if leftkey()=1
if cdir=2
PLAY SPRITE 1,7,9,100
if SPRITE FRAME(1)>9 then SET SPRITE FRAME 1,7
else
SET SPRITE FRAME 1,7
cdir=2
endif
dec xpos#,1.5
endif
if upkey()=1
if cdir=3
PLAY SPRITE 1,10,12,100
if SPRITE FRAME(1)>12 then SET SPRITE FRAME 1,10
else
SET SPRITE FRAME 1,10
cdir=3
endif
dec ypos#,1.5
endif
if downkey()=1
if cdir=4
PLAY SPRITE 1,1,3,100
if SPRITE FRAME(1)>3 then SET SPRITE FRAME 1,1
else
SET SPRITE FRAME 1,1
cdir=4
endif
inc ypos#,1.5
endif
sync
loop
http://dsarchy.deviantart.com/