Problems with timers

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
F.J. Sánchez
Posts: 10
Joined: Sun Nov 06, 2005 9:48 am

Problems with timers

Post by F.J. Sánchez »

Hi everybody,
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
Can any one help me?
Hack your mind
Okupa tu mente.
dkla
Posts: 21
Joined: Mon Oct 17, 2005 6:55 pm

Post by dkla »

Are you using LuaPlayer 0.15? Earlier versions had a problem displaying timers, but it has been fixed now. Give that a try.
F.J. Sánchez
Posts: 10
Joined: Sun Nov 06, 2005 9:48 am

I know this

Post by F.J. Sánchez »

But I'm using lastest version, 0.15. You can try it ;)
Hack your mind
Okupa tu mente.
Post Reply