A method I use for my animation is to manually control the frames.
Note: The following examples uses this image.
REM Using a variable to hold a pointer makes it much easier later on.
WalkSprite = 10
REM Creating the sprite frames.
create animated sprite WalkSprite,"Walk.png",3,2,1
REM Making an array to store what frames to use on a walk cycle.
dim AnimateWalk(9)
REM This is one method of storing data into an array.
for lp = 0 to 9
AnimateWalk(lp) = val(mid$("2211122333",lp+1))
next lp
REM Main Loop
do
REM WalkFrame will increment from 0 ~ 9 then back to 0.
inc WalkFrame#,.01
if int(WalkFrame#) => 9 then WalkFrame# = 0
REM Manually set the sprite frame using the array with WalkFrame# as pointer.
SET SPRITE FRAME WalkSprite,AnimateWalk(int(WalkFrame#))
REM Sprite onto the screen
sprite WalkSprite,100,100,1
sync
loop
Now in your case if you want it to perform a task when you press a button you would use a flag variable to toggle on or off an action.
REM Using a variable to hold a pointer makes it much easier later on.
WalkSprite = 10
REM Creating the sprite frames.
create animated sprite WalkSprite,"Walk.png",3,2,1
REM Making an array to store what frames to use on a walk cycle.
dim AnimateWalk(9)
REM This is one method of storing data into an array.
for lp = 0 to 9
AnimateWalk(lp) = val(mid$("2211122333",lp+1))
next lp
REM Main Loop
do
REM Space will check the current action and if it's zero then tasks an action.
if spacekey()
if ActionFlag = 0 then ActionFlag = 1
endif
REM This is the Standing Animation.
if ActionFlag = 0
REM The frame for just standing is AnimateWalk(0) which is frame number 2.
SET SPRITE FRAME WalkSprite,AnimateWalk(0)
endif
REM This is the Moving Animation
if ActionFlag = 1
REM WalkFrame will increment from 0 ~ 9 then back to 0.
inc WalkFrame#,.01
REM (Changed) Instead of only reseting WalkFrame# we also reset ActionFlag at the end of the animation.
if int(WalkFrame#) => 9
WalkFrame# = 0
ActionFlag = 0
endif
REM Manually set the sprite frame using the array with WalkFrame# as pointer.
SET SPRITE FRAME WalkSprite,AnimateWalk(int(WalkFrame#))
endif
REM Sprite onto the screen
sprite WalkSprite,100,100,1
sync
loop
You can have more than just 1 ActionFlag up to as many as you want and the same for the Animation arrays.