Don't you remember the code I wrote for you in your other thread about moving a sprite left and right? It did exactly what you are asking. The only difference was that it had eight frames of animation in each direction but now you only want two.
Here is the same code again:
Set display mode 640,480,32
`Make Background image
create bitmap 1, 640, 480
box 0,0,640,480,rgb(0,0,255),rgb(255,128,128),rgb(255,255,0),rgb(0,255,255)
get image 5,0,0,640,480,1
delete bitmap 1
`Make the four images
MakeImage("RIGHT FRAME 1", 1)
MakeImage("right frame 2", 2)
MakeImage("LEFT FRAME 1", 3)
MakeImage("left frame 2", 4)
x# = 100
y# = 100
speed# = 2.5
frame = 1
AnimSpeed = 100
sync on
sync rate 60
do
paste image 5,0,0
OldDirection = Direction
if LeftKey()
if LeftPressed
if Timer() > LeftPressed + AnimSpeed
LeftPressed = Timer()
inc frame
endif
else
LeftPressed = Timer()
inc frame
endif
dec x# , speed#
Direction = 2
endif
if RightKey()
if RightPressed
if Timer() > RightPressed + AnimSpeed
RightPressed = Timer()
inc frame
endif
else
RightPressed = Timer()
inc frame
endif
inc x# , speed#
Direction = 0
endif
if frame > 2 then frame = 1
sprite 1, x#, y#, frame + Direction
sync
loop
Function MakeImage(T$,I)
W = Text width(T$)
H = Text Height(T$)
create bitmap 1, W, H
text 0,0,T$
get image I,0,0,W,H,1
Delete Bitmap 1
endfunction
The only thing I have changed is to set the maximum value for the
frame variable to 2 instead of 8. I have also added a function to create the animation frames so that you can run it media free instead of downloading the sprite I used last time and you now have a background.