Frame by Frame Advance
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 21
- Joined: Fri Nov 02, 2012 10:23 pm
Frame by Frame Advance
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
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
Re: Frame by Frame Advance
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
http://www.love2d.org/wiki/love.run
Re: Frame by Frame Advance
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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Frame by Frame Advance
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:
If you want to step a single frame, just set do_step = true in love.keypressed() or where-ever you want it.
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
Help us help you: attach a .love.
-
- Prole
- Posts: 21
- Joined: Fri Nov 02, 2012 10:23 pm
Re: Frame by Frame Advance
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...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:If you want to step a single frame, just set do_step = true in love.keypressed() or where-ever you want it.Code: Select all
function love.update(dt) if is_playing or do_step then do_step = false -- normal update here end end
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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Frame by Frame Advance
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.
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.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests