# Cocos2d: Using single timer/scheduler for multiple sprites

want to know if is it possible to use single timer or scheduler method for multiple sprites ? Like I am now working on a game and there could be any number of sprites and i want to perform some actions on all of that sprites, So do I have to use as many timers or schedulers as sprites ? Or How can the job be done using only a single timer or scheduler ? What is I schedule a method and use it for, Say 10 sprites ? Will it affect the performance..?

## 1 Answer

Usually you'll just create one scheduler that calls the update method of your world/game. There you iterate through all entities/sprites and call their update method.

This gives you much better control about the flow of your code. You'll be able to run the physics-simulation first and then iterate through all bodies/sprites and update their position.

Having all entities within a data-structure also gives you greater control about when/how entities will be added and removed from updates as well as better means of debugging (scheduled updates can be cumbersome to debug if you have lots of sprites).

• @bummezack grat answer. I was looking to improve my code and was a bit stuck on this. I used entities cache handlers and within those was calling the update methods and overall my project is starting to be too complex now and there is the risk to loose control of it. Thanks :) – mm24 Sep 3 '12 at 16:19