views:

61

answers:

1

Hey Guys, It's me again with a Cocos2D problem. :-D

I create the main character of my upcoming game as a sublclass of NSObject. This class has a property for the Sprite, Spritesheet and all that stuff. But now I have the following problem.

I want to schedule a method for animating the sprite. That action which should be scheduled every second. But because I'm using a subclass of NSObject to hold all my data, I cannot use [self schedule:@selector(action:) interval:1.0]. Is there another way? I don't want to use NSTimer, because I then can't you the CCDirector anymore to break the game. It'd really be helpful if you could help me. :-D

Sandro Meier

A: 

Lots of ways to skin that cat, but here are a few:

  • Subclass CCNode instead of NSObject and call [yourClass schedule: interval:]
  • Expose a simplified selector that internally calls [self.sprite schedule: interval:]
  • Externally call [yourClass.sprite schedule: interval:]
  • Internally call [self.sprite schedule: interval:]
jtalarico
Thank you very much. I did it with the first way. But your 3th and 4th method don't work, because the methods I want to schedule are not in the CCSprite. They are in my NSObject Subclass. ;-)
Sandro Meier
Ah, well it was just a guideline since I didn't know what you were actually trying to schedule. Glad it worked out.
jtalarico
Ah ok. Thank you anyway. :-D
Sandro Meier