Artharos
Artharos

Reputation: 1077

Flash AS3 - Score counter

There's obviously a lot of posts about score counters and I have a counter that updates every frame (Enter_frame function) which works fine. The score variable increases every frame and thus the text field changes to display the score.

My problem is that on iOS it makes the app have some serious frame rate issues, I'm talking a 5-10 fps drop when the score ticker is enabled, it's very stuttery etc. I'm just wondering if there's some way around this, I presume it's because it has to update and redraw the text field every frame, but I can't see a way around that.

Any suggestions welcome,

Thanks!

Upvotes: 0

Views: 1001

Answers (2)

Joshua Granick
Joshua Granick

Reputation: 1037

Using a TextField with an opaque background, or changing to bitmap fonts, may help your performance.

For example, you could create separate bitmap images in advance, or at runtime you could use bitmapData.draw to generate separate BitmapData instances for each number you will need. Then you can swap bitmaps to display the correct score count.

You might also consider using NME in the future, which is very similar to Flash, but performs three to nine times faster than Adobe AIR for mobile platforms. For example, Iain Lobb's BunnyMark benchmark can render 500 bunnies, with rotation and alpha, at 16 FPS using Adobe AIR on an iPhone 4. NME renders 4750 bunnies at 30 FPS on the same device.

That's what I'm using to avoid performance issues

http://www.haxenme.org

Upvotes: 1

Kodiak
Kodiak

Reputation: 5978

You should redefine the score as a function of time.

score = t / 100; //where t is in milliseconds

At the beginning of your game, initialize a timer variable;

var start:Number = getTimer();

Then in your ENTER_FRAME listener, compute the score from the actual time and not the number of frames:

score = (getTimer() - s) / 100;

This is a performance-independant way to base the score on time.

Upvotes: 0

Related Questions