Framerate and frame skipping: what do you think?


(Alex K) #1

Hello.

Introduction

I have been using Flash and Flashpunk for only a few months. I am using a fixed frame rate of 30 FPS. I have about 300 entities (though the problem shows up even if I reduce to 50) and 65 MB of memory usage.

The Problem

I noticed that I get a fairly smooth framerate except that it skips every once in a while. The game logic operates normally but every once in a while the frame is not updated visually. This seems to happen independently of what is going on in the game. I have experimented with having the game just have a simple triangle float across the screen and no other code running. The triangle doesn’t float smoothly but seems to skip a lot. This happens more when I run the game on less powerful PCs and when I run the game in Flash Developer. However, the skipping doesn’t seem to happen as much when I run the game on more powerful PCs or from Firefox or Internet Explorer directly.

My Analysis

I suspect that Flash doesn’t get a steady amount of processing power because of other things running in the background. As a result, it sometimes doesn’t draw a frame when the computer is slightly busy with other things. Has anyone else encountered this problem? Is this normal or just me? Are there any work-arounds to solve this?

Thank you!


(rostok) #2

I would start by isolating the problem cause. Either it lies in Flash Player/System or in inefficient FP code. So I suggest running some example FP games and seeing if it happens as well. If it does - looks like it is the Player/System. If they run smoothly try stripping your code more and compare it to those working examples.

Don’t know your specs but I have a FP project with ~1.5k entities and +400MB ram running @30fps on Q8200.


(Zachary Lewis) #3

The reason you’re seeing more skips in FlashDevelop is because it’s using the debug player, while Firefox and Chrome use the release player, which doesn’t keep track of tons of debug data.

Secondly, you’ll get more skips in FlashPunk because it doesn’t offload any processing to the graphics card, putting all the strain on the processor. If you’re seeing hitches in framerate with a single entity on the screen, it’s a processor issue, not a memory issue.

Running at a higher framerate will help make the skips less noticeable, as will a variable timestep.


(Alex K) #4

I did as Rostok suggested and created a tiny project from one of the tutorials. Basically, a little plane that travels across the screen at 5 pixels per frame. You can see it here at 30 FPS, fixed framerate:

http://www.dreamspike.com/red/testplane.swf

It still stutters a little bit, so the issue is clearly the combination of FlashPunk + not a fast processor (1.8 Ghz here from a $400 laptop). Interestingly, the stutter still happened as I tried lowering the FPS or using a variable timestep. Apparently, the computer simply skips drawing frames every once in a while…regardless of how little this program wants to do and how few resources it needs.

Now, doubling the FPS (and dividing the speed by 2) does reduce the stutter, as Zach suggested. I suppose I just have to live with the fact that moving objects quickly across the screen will not be smooth on all computers and try to avoid that if I can.


(Zachary Lewis) #5

Perhaps it’s your movement code. I noticed the stuttering of the movement, but it seemed like it was stepping further than a previous frame.

Take a look at this movement test and tell me if it stutters on your machine too.


(rostok) #6

what about monitor refresh rate? if it isn’t exactly 30 fps there will always be a stuttering (or screen tearing).


(Alex K) #7

My monitor refresh rate is 60 Hz, which I think is pretty standard. There seems to be stuttering with Zach’s program as well. It is not as easy to see because many of the rectangles move slowly (less than 1 pixel per frame). The code I was using is below. I don’t think there are any problems with that. You will even see the variable timestep line I tried.

public class MyEntity extends Entity { [Embed(source = ‘player.png’)] private const PLAYER:Class;

	public function MyEntity()
	{	
		graphic = new Image(PLAYER);
	}
	
	override public function update():void
	{
		y = 10;
		x += 5;
		//x += (200 * FP.elapsed);
		//trace("MyEntity updates.");
		
		if (x > 800)
		x = 0;
	}
	
}

}


(Alex K) #8

Just to be sure, I took Zach’s code and sped up the rectangles to see if they would stutter. I also reduced their number and made them travel horizontally only. It seems like stuttering definitely occurs with this code. The only difference between Zach’s code and mine is that he calls super.update() and I do not. However, this seems to make no difference in performance.

Here is his program with the adjustment I described above: http://dreamspike.com/red/ztest.swf


(Zachary Lewis) #9

Are you noticing the framerate counter dropping noticeably when the stutters occur? I notice slight stutters, but not as bad as the original airplane demo you showed.

It may be an unavoidable problem with the way FlashPunk performs software rendering. :disappointed:


(Alex K) #10

The framerate displayed by the Console Debugger on this latest ztest.swf and all the other tests did not drop much. However, I did notice that it doesn’t stay at one number consistently. On the ztest, it dips to 58 (from 60) a lot. Also, on the 30 FPS ones, it dips to 28 or so quite frequently. This doesn’t seem to depend on what’s going on in the game (i.e. it dips even when a single object is moving as in our tests).


(Ultima2876) #11

I’ve seen this problem and been aware of it for years - but there’s no fix. It just ‘is’, and will happen regardless of your movement code, system etc. After a few years you’ll begin to phase it out automatically. It’s also nothing to do with the particular engine - it seems to do it with flixel and PushButton Engine also.

It is also not a performance problem - your game can be running at a solid framerate, using 5% of the CPU and you’ll still get the visual jitter. Luckily it seems to be only limited to the debug desktop projector as you say - in release mode on the release player everything is fine (which is what matters - that will be where the players are playing your game, after all).

The dip in fps can be safely ignored as that’s a separate thing that has nothing to do with the visual jitter (games written in C++ also run at 58-60 fps and shuffle around).


(Alex K) #12

It is definitely better in Release mode. Also, going with 50 FPS over 30 FPS seems to help. If frames are going to be skipped every once in a while, it is less notice-able when there are more of them. I ended up converting my graphics from 30 to 50…and the difference in quality is big.


(Ultima2876) #13

You might find you’re better going to 60fps - 50 used to be somewhat popular thanks to PAL territories but thanks to almost 100% of monitors using a refresh rate of 60hz, 60fps gives better frame-locking with vertical synchronisation.