I’m trying to add animations to my game (iPhone app, using cocos2d).
The game was written in C++, and now I want to run it on iPhone, so most of the classes are in c++.
The thing looks like that.
I’m creating CCSprite,CCAction in obj-c class in init function, and then run CCAction on sprite.
And animation is working.
But I want to put this CCSprite and CCAction variables in my C++ class.
I create *CCSprite in init class and send this pointer to the c++ class. Then, I create CCAction and run it on the sprite.
And after that, when in my init function (obj-c class) do:
return self;
then the app is running, running and running and nothing happens. I receive only this message in console:
* Assertion failure in -[CCSprite setTexture:], /Users/Michal/…./libs/cocos2d/CCSprite.m:898
Terminating in response to SpringBoard’s termination.
I dont know what should I do next…
Is it possible to keep CCSprite/Action etc. in C++ class succesfully?
Make sure you have properly initialized the texture before you try to use it like this:
then initalize the sprite (or sprite subclass – in this example spuButton is a subclass of CCSprite) :
Note: since it is a subclass i had to setup the init methods for it like this (You must do this if you subclass CCSprite):