dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [as3] Looping Timer vs. Enterframe

  1. #1
    Senior Member charlie_says's Avatar
    Join Date
    Feb 2003
    Location
    UK
    Posts
    508

    [as3] Looping Timer vs. Enterframe

    Quite a few examples of AS3 stuff I've looked at have used something like

    code:

    myTimer.addEventListener( TimerEvent.TIMER, gameLoopFunction );



    rather than using

    code:

    myTimer.addEventListener( Event.ENTER_FRAME, gameLoopFunction );



    I wondered if AS3 offered any particular advantage of using one method over the other?

  2. #2
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    "myTimer.addEventListener( Event.ENTER_FRAME" ???

    There's plenty of material on this if you search for it, but from what I can remember it's better to use ENTER_FRAME I think.

  3. #3
    Senior Member charlie_says's Avatar
    Join Date
    Feb 2003
    Location
    UK
    Posts
    508
    Well, I did have a look, and there wasn't so much consensus.

    From what I understand, both will be susceptible to inaccuracy/lag from CPU load - but what you should be able to ensure with Timer is that animations are smoothly handled over time.

    My experience with AS2 dev is that I always used onEnterFrame and never setInterval which appears to be the nearest equivalent. And to ensure that playback was pretty steady I made sure my code was optimised, and where there needed to be code heavy bits I tried to smooth them out (over a few frames say.)

    What I wondered was whether anyone had made a game and switched between the two, and had empirical results they could share about the process...

  4. #4
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    if you want any kind of accuracy, you'll have to manage time yourself either way, so it really doesn't matter in that respect. listening to a DisplayObject's ENTER_FRAME event has the added advantage of being tied to rendering. if you really have one game loop (where rendering is obviously a, probably last, step), the Timer method runs you the risk of rendering twice (or more!) before anything's drawn to screen.

  5. #5
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Check the tutorials by Jeff Fulton, for example this one called "Tutorial : Creating an Optimized AS3 Game Timer Loop":
    http://www.8bitrocket.com/newsdispla...newspage=10248
    You can get the source fla from there too.

    I have used simple EnterFrame in all my games.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center