So the ENTER_FRAME property will add an object to the stage on every frame the game runs. If the game is 24 fps, 24 objects created per second. How can I limit that so it will generate an object every 4 frames?
you can have a counter that increments every frame
var f:int = 0;
addEventListener(Event.ENTER_FRAME,onEnterFrame);
function onEnterFrame(e:Event):void{
if (f%4 == 0){
// do something
}
f++;
}
you can set f=0;
inside the if statement if you like
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.