iPhone - cocos2d - 动画和C ++类 [英] iPhone - cocos2d - Animations and C++ class
问题描述
我想为我的游戏添加动画(iPhone应用程序,使用cocos2d)。
I'm trying to add animations to my game (iPhone app, using cocos2d).
游戏是用C ++编写的,现在我想运行它在iPhone上,所以大多数类都是在c ++。
The game was written in C++, and now I want to run it on iPhone, so most of the classes are in c++.
事情看起来像。
我在init函数中创建CCSprite,CCAction在obj-c类中,然后在sprite上运行CCAction。
和动画是工作。
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.
但我想把这个CCSprite和CCAction变量在我的C ++类。
我在init类中创建* CCSprite,并将这个指针发送到c ++类。然后,我创建CCAction并在精灵上运行它。
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.
然后,当我的init函数(obj-c类)do:
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:
* 声明失败 - [CCSprite setTexture:], /Michal/..../libs/cocos2d/CCSprite.m:898
终止响应SpringBoard的终止。
* Assertion failure in -[CCSprite setTexture:], /Users/Michal/..../libs/cocos2d/CCSprite.m:898 Terminating in response to SpringBoard's termination.
我不知道下一步我应该做什么...
是否可以成功地保持CCSprite / Action等在C ++类中?
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:
CCTexture2D *redButtonNormal = [[CCTextureCache sharedTextureCache] addImage:@"RedButtonNormal.png"];
/ p>
then initalize the sprite (or sprite subclass - in this example spuButton is a subclass of CCSprite) :
spuButton *redButton = [spuButton spuButtonWithTexture:redButtonNormal];
注意:因为它是一个子类,我必须像这样设置init方法如果你子类化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):
+ (id)spuButtonWithTexture:(CCTexture2D *)normalTexture
{
return [[[self alloc] initWithTexture:normalTexture] autorelease];
}
- (id)initWithTexture:(CCTexture2D *)aTexture
{
if ((self = [super initWithTexture:aTexture]) ) {
state = kButtonStateNotPressed;
}
return self;
}
这篇关于iPhone - cocos2d - 动画和C ++类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!