Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Multiple ENTER_FRAME event listeners — Gideros Forum

Multiple ENTER_FRAME event listeners

freesspfreessp Member
edited May 2015 in Game & application design
Would it be better (performance-wise) to have multiple ENTER_FRAME event listeners for different actions, or to have one ENTER_FRAME event listener to handle all activities that are to occur on every frame? For example, I have two images that scroll down the screen and then repeat to simulate continuous movement. I also check to make sure that my HUD is always at the front of the stage hierarchy. Right now, I have an ENTER_FRAME event listener for each one. So, would it be better to place all three into one function so there is only one ENTER_FRAME event listener, or is it better to have separate event listeners for each one, or is the number of calculations the same either way resulting in no difference in performance?

Comments

  • tkhnomantkhnoman Member
    Accepted Answer
    Regarding HUD, would it be better if you have 2 or more main group (spirte object)
    For example, there is Player Group, UI Group, background Group.
    Then you add all UI at UI Group, all objects at Player Group, and all background at background Group?

    Regarding Enter_Frame, i checked far in the past, and there is no much different between those two way in term of speed. It just the matter of whether you want an enter frame to not overlap each other or not.
    For example, if you add enter_frame to Character to handle it's movement, while camera also moving, it would be much better to add camera handler at the same enter_frame, after the character movement.
  • freesspfreessp Member
    Thanks @tkhnoman, that is what I thought regarding speed. It shouldn't matter if you do one thing ten times or ten things one time, but I wasn't 100% sure. Sometimes simple things make a speed difference even though they seem the same (like multiplying by 0.5 is faster that dividing by 2). Adding a separate event listener for each makes my code easier to follow, but having only one makes for less code, and I only have to have one removeEventListener (if needed).

    As for the HUD (which is just buttons and a score counter at this point), I have lots of "enemies" and "bullets" being added and removed from the stage all the time. I was have problems with them being on top of the buttons. Adding a quick check at every enter_frame to say, "if the hudGroup is not at the front (bottom) of the stage hierarchy, then move it there, " was a quick and easy fix. There is probably a better way to do this, as you suggested, and I will probably make some changes later.

    Thanks again!
Sign In or Register to comment.