问题描述
我使用Cocos2d 2.1rc0。
I am using Cocos2d 2.1rc0.
我有这个项目,当我没有使用CCSpriteBatchNode工作完美。然后我决定使用批处理节点来减少绘制调用,我的问题开始了。
I have this project that was working perfectly when I was not using CCSpriteBatchNode. Then I decided to use batch nodes to reduce draw calls and my problems started.
很多东西都不能正常工作。 reorderChild是一个。另一个是runAction,没有runAction Cocos是没用的。
A lot of stuff is not working well. reorderChild is one. Another one is runAction and without runAction Cocos is useless.
这是一个不使用batchNodes而不使用它的方法示例。
This is an example of a method that works without batchNodes and do not work with it.
// move/rotate all objects
for (int i=0; i<[allObjects count]; i++) {
Card *object = [allObjects objectAtIndex:i];
[object stopAllActions];
CGPoint center = object.position;
center.x = center.x + 100;
center.y = center.y - 200;
CCMoveTo *moveAction = [CCMoveTo actionWithDuration:0.3f position:ccp(center.x, center.y)];
CCRotateTo *rotateAction = [CCRotateTo actionWithDuration:0.3 angle:0.0f];
CCSpawn *action = [CCSpawn actions:moveAction, rotateAction, nil];
[object runAction:[CCSequence actions: action,
[CCDelayTime actionWithDuration:0.1f],
nil]];
}
完全没有任何反应。
我试图消除CCSpanw和使用runAction直接只是与移动和没有工作。如果我使用常规精灵,它工作。
I have tried to eliminate the CCSpanw and use runAction directly just with move and nothing works. If I use regular sprites, it works.
该数组中的对象派生自基于CCSprite的类。
Objects in that array derive from a CCSprite based class.
是否有任何解决方法?
推荐答案
解决方案是将类转换为从数组提取的对象...
the solution is to cast the class to the object extracted from the array...
而不是
Card *object = [allObjects objectAtIndex:i];
此
Card *object = (Card *)[allObjects objectAtIndex:i];
这篇关于runAction不适用于来自CCSpriteBatchNode的sprites的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!