Trying to make a Game and Watch-style game - help with timers?


I've been trying to make a Game and Watch style game, where each frame pops in one-after-another after an amount of time. Specifically, I'm trying to reproduce the top walking person in Manhole, at the moment.

I was attempting to use a keyRepeatTimerWithDelay to increment up a variable, hoping to pass that variable into some if/thens to make one frame appear and another disappear.

I can get the variable to increment up by 10 on each delay, but I can't pass that value into the if/then to make Sprites appear and disappear.

Can anyone provide a little guidance about what I'm doing wrong? My assumption is that I don't quite know how to actually print the variable to be accessed in the update function, but I'm at a loss for the moment.

The intention is to have the enemy walk across the screen and then disappear. Later, I'll have a spawner work more in, but I'm just trying to get it to animate correctly first.


variable = 0

local topWalkerTimer = pd.timer.keyRepeatTimerWithDelay(500, 500, function()
    variable = variable + 10
    --print (variable)

function topWalker:update()    
    if variable == 10 then
    variable == 20 then
    variable == 30 then
    variable == 40 then
1 Like

Ok I admit I was genuinely curious (deleted my earlier reply because it was wild speculation). Instead here's an implementation of a simple walking frame delay timer. I've used an imagetable instead of sprites, as sprites in the SDK are a little 'heavier' because they support collision detection and a bunch of other handy things related to that which may? or may not be required depending on how you're building a Game&Watch style game. I can see with a few imagetables and a list of fixed screen locations you could quickly build a mock 'LCD screen' like the Game&Watch devices used.

import 'CoreLibs/timer'

-- Image management
local walkerTable, err ='helmet-table-64-80.png')
assert(walkerTable, err)

-- Timer management
local counter = -1 -- Shady? But if we start at zero, initial timer firing means we draw frame 2 first.
local timer = playdate.timer.keyRepeatTimerWithDelay(500, 500, function()
    counter = counter + 1
    -- counter +=1 is also an option

-- Main loop
function playdate.update()

    -- Pick a frame
    local frame = 1 + (counter % walkerTable:getLength())
    -- print(frame)

    -- Draw the frame, offset 80 pixels horizontally depending on frame number., 0, 400, 90)
    walkerTable:getImage(frame):draw(80 * (frame - 1), 10)

The image table used is attached and is just quickly lifted from a Helmet game screenshot.


I think the cause of your initial issue might simply be you're missing the playdate.timer.updateTimers() call?

Looking at this code you could just ditch the counter variable entirely and make the frame calculation in the timer callback directly. Ah well, I tried to keep it similar to your example above.

Here's the .pdx as well (8.7 KB)

Snic, thanks for replying!

I don't have the code handy (sneaking in a little forum-read at work), but playing around a bit yesterday I was able to get at least the 'move 80 pixels horizontally depending on the frame number' part to work. I re-set up the 'topwalker' character from Manhole using an imagetable, as you suggested, but still had some difficulty.

My trouble still seems to be making the animation advance with the frame. I wasn't able to open your output in the simulator, unfortunately.

I'm setting up 'topwalker' in a separate .lua file to keep my main.lua streamlined - I wonder if I missed a 'self.' or something.

Any advice on making the frames of animation advance correctly? I really thought this part would be simple to code, hah!