Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

Help animating sprites

A topic by bert003 created Jan 06, 2020 Views: 467 Replies: 2
Viewing posts 1 to 2
(2 edits)

Hi all,

I have just started experimenting with TIC 80 and am sort of stuck animating a 2x3 sprite (refer to attached image).



I would like to animate it when moving (pressing left and right arrow) in a smooth way (not glitchy).

x=10
y=80
sn=0
function aspr() sn=0+t%16//8*2 end
function TIC()
    cls(7)
    spr(sn,x,y,1,1,0,0,2,3)
    if btn(2) then aspr(); x=x-0.5
    elseif btn(3) then aspr(); x=x+0.5 else sn=0 end
end

Obviously this code is far from perfect. Let's say it works but if I quickly press and release the arrow keys the player sort of slides without being animated.

The sprite is not mine (I am just experimenting as I said) but I would like a smooth walking transition. I thought of changing the aspr() values to 16 and 8 to quickly cycle between the sprites. I am also incrementing x by 0.5 no to make the player go so fast. Not sure if I am doing well.

Can someone give me a helping hand to optimise the code in the correct way?

Thanks in advance

(1 edit)

A simplistic method. Checks if a button is down and 10 ticks have elapsed, if so changes to next animation frame (in this case that's just sprite 0 or 2) and moves sprite by 1 pixel: You could add more animation frames and change the value of 'f' being checked. Hope that's some use...


x=10
y=80
t=0 - ticks
f=0 -- animation frame

function TIC()
    cls(7)
    spr(f,x,y,1,1,0,0,2,3)
    if btn(2)and t%10==0 then
                    f=f-2
                    x=x-1
                    if f==-2 then f=2 end -- wrap around
    elseif btn(3) and t%10==0 then
                    f=f+2
                    x=x+1
                    if f==4 then f=0 end -- wrap
   end
   t=t+1
end

Thanks mr_happy. That is exactly what I was looking for!

Appreciate you taking time to help me...