tags:

views:

35

answers:

1

Hey, I'm writing game for iPhone, using cocos2d framework.

I have 100 sprites and I want to run on them the same animation. Do I have to create 100 separate actions for each sprite, or can I create one action and use it on every sprite?

A: 

One method which i follow is that I create an derived class from sprite class and assign actions in the class initialization .

For example i have to generate 10-100 enemy sprite

i'll make a class enemyActoor.mm derived from CCSprite

their i keep a funtion

+(void)initwithParamters:(CCPoint)spwanPoint  frames:(NSString *)plist{

mummyActor *tempInstance =[mummyActor spriteWithWatever suites ur reqirment];

//do all stuff here 
//load actions

return tempInstance;

} 
//other methods to call actions or access mutators 

when i need to generate these enemies i create n NSMuTableArray enemyLoaded and keep all instance in this array ....

when applying various pathfinding algo or rules as per game i access each objects from these array ///

Sorry for poor english but this is the best way i found till now to get work done without asking anyone ;)

lonewolfaka9
Hmm. I find out something. I have definied "action", and I use this action to animate my sprite. But when I want to run later another animation on this same sprite I receive EXC_BAD_ACCESS. But when I use "action", and then do sth like that: "action = [Animation newAnim];", and then run on this sprite, everything works fine. But I dont want to create new action during the game, but in init function, and then run it.
Moriquendi