Page 1 of 1

Frame by Frame Advance

Posted: Mon Aug 26, 2013 8:06 pm
by TheConfuZzledDude
I'm starting to make a game, and one of the main features that I want in this game is the ability to freeze the game entirely, and have it advance frame by frame, much like emulators are able to do. I've been thinking of ways to do it, but the only things I can think of are capping the framerate at 0 frames per second and then capping it to 1 fps for a second, or pausing the game completely then unpausing and immediately pausing it again as soon as possible. Do you guys know any better way to do this?

Re: Frame by Frame Advance

Posted: Mon Aug 26, 2013 8:22 pm
by Eamonn
The only thing I can think of is love.timer.sleep(). It seems like it's what your looking for.

Re: Frame by Frame Advance

Posted: Mon Aug 26, 2013 8:24 pm
by Plu
Change love.run function. That's the one that calls love.update; you can add in some controls to make it not be called (which will freeze your game) as well as controls to call it once (which will give you frame-by-frame play) or just call it regularly (to speed gameplay back up)

http://www.love2d.org/wiki/love.run

Re: Frame by Frame Advance

Posted: Mon Aug 26, 2013 8:28 pm
by Eamonn
Oh! I've never heard of love.run! From the sounds of it, that's a much better solution!

Re: Frame by Frame Advance

Posted: Mon Aug 26, 2013 8:48 pm
by Robin
I'd suggest that instead of changing love.run(), you wrap all your code in love.update() inside an if-statement. That way, you can decide that certain things need to be updated even if the game is paused.

This is what I mean:

Code: Select all

function love.update(dt)
    if is_playing or do_step then
        do_step = false
        -- normal update here
    end
end
If you want to step a single frame, just set do_step = true in love.keypressed() or where-ever you want it.

Re: Frame by Frame Advance

Posted: Mon Sep 02, 2013 5:16 pm
by TheConfuZzledDude
Robin wrote:I'd suggest that instead of changing love.run(), you wrap all your code in love.update() inside an if-statement. That way, you can decide that certain things need to be updated even if the game is paused.

This is what I mean:

Code: Select all

function love.update(dt)
    if is_playing or do_step then
        do_step = false
        -- normal update here
    end
end
If you want to step a single frame, just set do_step = true in love.keypressed() or where-ever you want it.
That seems to work, but there is just one thing: I have a for loop inside of it that prints out items from a list, and when I set dostep to true, it does the whole loop instead of just giving me the first item when I press the button, and the next when i next press the button. Do for loops run independently from the function they're in being called? If so, does that mean I have to make my own loop function that doesn't use for? Sorry if that seems confusing...


EDIT: Just tried

Code: Select all

if i <= 4 then
      i = i + 1
      print (char.test[i])
      if i == 4 then
        i = 0
      end
    end
and it works exactly how i wanted it to...

Re: Frame by Frame Advance

Posted: Mon Sep 02, 2013 5:29 pm
by Robin
Okay, so you are confused about when code is run. Code just runs and keeps running, generally. Before love.update() is called, the default love.run gives control to the operating systems, so that you can move your mouse and press buttons and other programs get a slice of CPU too (this isn't true, but that doesn't matter right now). Everything after the control is given back to LÖVE runs at once, in a single frame, up until control is given back to the operating system.

To do what you want to do, you wouldn't use a loop, but a counter, that you increment when that button is pressed.