I'm trying to do an animated character using a tile set. I'm doing this with timers, but it's no very accurate, this code for example sometimes works, sometimes doesn't, aprox 2 of 10 times works and 8 doesn't. You can try this if you don't believe me!
Code: Select all
System.usbDiskModeActivate()
sprite = 1 -- First sprite to show
dir = 1 -- Direction of the animation effect
delay = Timer.new()
-- Loading of images
fondo = Image.load("fondo.png");
sprites = Image.load("sprites1.png");
while true do
screen:blit(0, 0, fondo, 0, 0, fondo:width(), fondo:height(), false)
-- This part must update the sprite to be displayed each 200ms
-- but I only can 600ms
time1 = math.floor( delay:start()/100)
if time1 == 5 then -- Change 5 to 6 and always will work
if dir == 1 then
if sprite == 5 then
dir = 0
sprite = 4
else sprite = sprite + 1
end
else
if sprite == 2 then
dir = 1
sprite = 3
else sprite = sprite - 1
end
end
delay:reset()
end
screen:print(20,10,fuck)
posX = 1*sprite + 37*sprite
screen:blit(20, 210, sprites, posX, 0, 37, 48, true)
screen.waitVblankStart()
screen.flip()
pad = Controls.read()
if pad:start() then
break
end
end