this is example code.
set window on
sync on : sync rate 60
create animated sprite 1,"02.png",5,4,1
x=100
y=200
state=0 ` State flag , global
do
if upkey()=1
y=y-1
if state<>1 then state=1 : set sprite frame 1,2
play sprite 1, 2, 5,100
else
if downkey()=1
y=y+1
if state<>2 then state=2 : set sprite frame 1,12
play sprite 1,12,15,100
else
if leftkey()=1
x=x-1
if state<>3 then state=3 : set sprite frame 1,17
play sprite 1,17,20,100
else
if rightkey()=1
x=x+1
if state<>4 then state=4 : set sprite frame 1,7
play sprite 1, 7,10,100
endif
endif
endif
endif
sprite 1,x,y,1
sync
loop
https://forumfiles.thegamecreators.com/download/2433508