Frame by Frame Advance

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheConfuZzledDude
Prole
Posts: 21
Joined: Fri Nov 02, 2012 10:23 pm

Frame by Frame Advance

Post 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?
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Frame by Frame Advance

Post by Eamonn »

The only thing I can think of is love.timer.sleep(). It seems like it's what your looking for.
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Frame by Frame Advance

Post 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
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Frame by Frame Advance

Post by Eamonn »

Oh! I've never heard of love.run! From the sounds of it, that's a much better solution!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Frame by Frame Advance

Post 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.
Help us help you: attach a .love.
TheConfuZzledDude
Prole
Posts: 21
Joined: Fri Nov 02, 2012 10:23 pm

Re: Frame by Frame Advance

Post 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...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Frame by Frame Advance

Post 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.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests