Is it a bad idea to implement a timer loop in Flex?

In our game project, we had a timer installed, which worked approximately 20 times per second (the same as the application frame rate). We use this to move some sprites. I am wondering if this can cause problems, and should we update them with the EnterFrame event handler instead? I get the impression that having a timer loop runs faster than the application frame rate is likely to cause problems ... is this the case?

As an update, trying to do this on EnterFrame caused very strange problems. Instead of a frame every 75 ms, he suddenly jumped to 25 ms. Please note that not only our calculation claimed that the frame rate was different, suddenly the animation accelerated to an insane speed.

+3
source share
5 answers

I would go to the Enter frame, in some special cases it may be useful to have two “loops” for logic and one for visual effects, but for most games I do that I bind to the receiver Enter frame-event, Having a separate timer to move your the material is a little unnecessary because it is tuned to anything except that the frame rate will make the movement sharp or simply not visible (since the frame is not redrawn).

One thing to consider is to separate your logic from the frame rate, this is easiest to achieve using getTimer (available in both as2 and as3) to calculate the time elapsed since the last frame, and adjust the movements or something else accordingly.

, , , , , , , .

+4

, Flash , .

, -, Flash ( ), . 10 , 50 . , , Flash - :

  • (1000/) , ?
    • :
    • : :
      • () .
      • ( ENTER_FRAME

(, , ) . , , , . - , updateAfterEvent() ( AS2, AS3).

, . , , 50 , - , , enterFrame ( ).

+4

- , , .

. , , , , , .

+2

, timerEvent Enter Frame , . ( timerEvent ?)

PS: , , , "" .

0

, TweenLite (http://blog.greensock.com/tweenliteas3/), 3 , TweenMax, , , 11kb. . -, "" . , AS3 1500 TweenLite, 20 , , Tweener, 9 fps http://blog.greensock.com/tweening-speed-test/. , .

//Make sure you have a class path pointed at a folder that contains the following.
import gs.TweenLite;
import gs.easing.*;

var ball_mc:MovieClip = new MovieClip();
var g:Graphics = ball_mc.graphics;
g.beginFill(0xFF0000,1);
g.drawCircle(0,0,10);
g.endFill();

//Now we animate ball_mc
//Example: TweenLite.to(displayObjectName, totalTweeningTime, {someProperty:someValue,anotherProperty:anotherValue,onComplete:aFunctionCalledWhenComplete});
TweenLite.to(ball_mc, 1,{x:400,alpha:0.5});

, ball_mc 400 x, Tween 0,5.

1 , . , , , - Expo.easeOut(Strong easeOut). , , .

TweenLite.to(ball_mc, 1,{x:400,alpha:0.5,ease:Bounce.easeOut});
TweenLite.to(ball_mc, 1,{x:400,alpha:0.5,ease:Elastic.easeOut});

gs.easing. * import, , , Penner Easing Equations, TweenLite.

, (Open Loops) , Timer, , .

It is also important to note that TweenLite and TweenMax offer much more than I showed here, and it is safe to say that I use one of two classes in each individual project. Animations are common, they have functionality attached to them (onComplete: functionCall), and again they are optimal and resource-friendly.

0
source

Source: https://habr.com/ru/post/1697443/


All Articles