At 11/7/10 08:39 AM, Chickumbleh wrote:
At 11/7/10 08:23 AM, Archawn wrote:
Cumulative Snow
Can you show the source for the fps counter? I've never understood how to make them.
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.getTimer;
public class FPSCounter extends Sprite{
private var last:uint = getTimer();
private var ticks:uint = 0;
private var tf:TextField;
public function FPSCounter(xPos:int=0, yPos:int=0, color:uint=0xffffff, fillBackground:Boolean=false, backgroundColor:uint=0x000000) {
x = xPos;
y = yPos;
tf = new TextField();
tf.textColor = color;
tf.text = "----- fps";
tf.selectable = false;
tf.background = fillBackground;
tf.backgroundColor = backgroundColor;
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
width = tf.textWidth;
height = tf.textHeight;
addEventListener(Event.ENTER_FRAME, tick);
}
public function tick(evt:Event):void {
ticks++;
var now:uint = getTimer();
var delta:uint = now - last;
if (delta >= 1000) {
var fps:Number = ticks / delta * 1000;
tf.text = fps.toFixed(1) + " fps";
ticks = 0;
last = now;
}
}
}
}
To add one:
addChild(new FPSCounter());
Also, to keep fps down are you caching as bitmap?
Each flake is a sprite, and as they hit the pile of snow or the bottom of the screen, they are added to a BitmapData instance and deleted.
Currently they are not cached as bitmaps, as I did not encounter any lag. If it starts to lag, I'll do that--I just don't want to sacrifice CPU usage for a few hundredths of FPS optimization.