Hey everybody!
I have built some pretty complicated game logic and now I’m deeply in performance improving process.
My question is: in general should I try to avoid using many enterFrame runtime listeners even if it makes architecture more complicated?
Example:
Say I have two objects - a player and a ball. Player is moving so I set an event listener:
[lua]local function trackPlayer()
playerObj:translate(dx,dy)
end
Runtime:addEventListener(“enterFrame”, trackPlayer)
[/lua]
I want to know when the ball occurs behind player:
[lua]local function trackBall()
if(playerObj.x > ballObj.x) then
– something here
end
end
Runtime:addEventListener(“enterFrame”, trackBall)
[/lua]
In this example I could easily merge this two tracking functions into one. But in real project things are much complicated, there are many dynamically added objects trying to detect player position and do something. So programmatically it’s much easier to create new runtime enterFrame listener on each object but those listeners would be still pretty light and easy.
On the other hand I can implement some new algorithms to bring all those objects into one tracking function and that function will loop through my objects array and perform the same actions.
So whats faster?
Any help is appreciated, thank you!
Best regards,
Anton