PDA

View Full Version : Frame render skip dumping



Tokeijikaku
July 10th, 2009, 09:56 AM
(I don't really know what it's called)

You know how most "regular" games don't actually slow down when the framerate drops, but flash games do? Regular games just lose the frames that can't be rendered within the time constraint and instead give you choppy cam.

Well I tried to recreate the effect by having everything run on a 16+(1/3*2) interval timer and leave enterFrame out of it altogether. But when the framerate drops, the timer goes along and everything slows down.

HNGF! That means the timer isn't really independent from the actual framerate and thus a piece of junk!

Is there any way of creating the render skip thing I'm trying to do??

mxrider108
July 10th, 2009, 11:23 AM
You could make all your objects that move do so using a time-based system (they keep track of the time between frames and move the distance which corresponds), or you could look into an "active rendering" system, which is simpler. Tutorial here: http://www.8bitrocket.com/newsdisplay.aspx?newspage=10248

flyingmonkey456
July 10th, 2009, 04:30 PM
first of all, find how many px per second you want things to be going. say the base framerate is 30 and you have an object that is moving at 5 px per frame. that would be 150 px per second. now lets say you lowered the 30 px per frame to 5 px per frame and you still need it to move at 150 px per second. you would get the new px per frame by dividing the px per second by the framerate. 150 / 5 = 30 px per frame.
simple as that :)

bluemagica
July 10th, 2009, 06:54 PM
Use as3, and use the Timer class! Then read "optimised game loop" article on 8bitrocket.com!

mxrider108
July 12th, 2009, 01:18 AM
Use as3, and use the Timer class! Then read "optimised game loop" article on 8bitrocket.com!
Haha yup, that was the link I posted :-P

SparK_BR
July 13th, 2009, 03:32 AM
when using AS2 don't use getTimer() but setInterval() and clearInterval(), they work ok for me.

therobot
July 13th, 2009, 12:12 PM
when using AS2 don't use getTimer() but setInterval() and clearInterval(), they work ok for me.

That is inaccurate advice. AS3 uses the Timer & TimerEvent classes, as2 uses setInterval & clearInterval. Both as3 & as2 have getTimer, which will tell you how much time has passed in the flash movie since its creation (expressed in milliseconds).

DrRobot
July 13th, 2009, 10:59 PM
Can't you do something with getTimer()?

flyingmonkey456
July 13th, 2009, 11:10 PM
guys, the simplest way is the way i said. for every variable that determines speed or rate, use the equation i said above to keep it from changing with the framerate. for example, instead of simply saying "speed = 5" you would say "speed = pps/_framerate". pps can be gotten by multiplying the speed needed at a given framerate by that given framerate.

senocular
July 14th, 2009, 09:47 AM
Wrong! Don't use setInterval or the Timer class. You want to use an enter frame loop and keep track of time with getTimer.

Timer and intervals are dependent on the set frame rate and still suffer from the effects of poor performance. They can also result in queuing where multiple Timer events to be stuck in a bottleneck and end up getting called all at once.

The enterFrame event matches Flash Players ability to render to the screen. By rendering in that event, you're rendering to the FPS of what Flash Player is capable. What you render should be based on the time it takes to get from one frame to the next. If it takes 30 ms, then render what should be seen 30 ms since the last frame. If it takes 1000 ms, then render what should be seen then (effectively skipping all the states in between)

SparK_BR
July 16th, 2009, 09:21 AM
Wrong! Don't use setInterval or the Timer class. You want to use an enter frame loop and keep track of time with getTimer.
[...]


hmm... i think you didn't get what he wants

it's not about the render loop (put things in the screen), but making the physics loop, which should not appear on the screen since it's only maths (think of it as a double buffer), you must test collision and other things doesn't matter if gfx are laggy, you are calculating the physics which don't rely on gfx (at least mine don't)

a moving object should be in the same place it would if FPS were higher, you simply didn't render some of it's steps.

hmm... i think an attachment is better than my broken english...

in this sample there's a TPS and an FPS
change the FPS and see how the TPS still works without updating screen

BoppreH
July 16th, 2009, 10:05 AM
Spark, what senocular is saying is that the Timer class speed depends on the movie's frame rate, i.e.: the slower the movie is, the slower the Timer will run.

Yeah, it's supposed to be in MILLISECONDS, not FRAMES, but that's how it works.

I can't explain very well what's the difference, so I changed your test to implement senocular's idea. It might look the same, but this one will not slow down when the cpu usage raises.

BoppreH
July 16th, 2009, 10:20 AM
It's a double post, but I think the reason is good enough.

I added a very slow function to Spark's and senocular's implementations (timer tick / enter frame + getTimer). Both of them were made to rotate the ball in similar speeds, but Spark's obviously does not, while senocular's skip frames like mad.

It's not pretty, but it does skip frames and this is the whole point.

SparK_BR
July 17th, 2009, 12:32 AM
hmm... i didn't expect the code to be heavy, but the gfx...

but ok, i stand corrected

Tokeijikaku
July 17th, 2009, 01:14 AM
I think I got it, check it out! [EDIT: Don't check it out at this time >.< failed revision]

Surprisingly simple, actually.
Too bad I can't upload it, since despite it's simplicity, it's 971 kB after save and compact.

And then I save as and it's suddenly 336 kB. What's that all about?!