在cocos2d iphone中尝试停止精灵操作时出现断言失败错误
我在停止行动方面有问题。我有两个精灵动画,一个是蚂蚁,第二个是蚱蜢。当我只是调用ants动画时,它工作得很好,但当我尝试运行ant和grasshopper动画时,它会给我带来错误。 *在-[CCSpriteBatchNode addChild:z:tag:]、/Users/zohaib/Downloads/zohaibgame/zohaibgame/libs/cocoos2d/CCSpriteBatchNode.m:183中断言失败 它在调用antMoveEnded时给出错误 蚂蚁动画代码在cocos2d iphone中尝试停止精灵操作时出现断言失败错误,iphone,ios,objective-c,cocos2d-iphone,Iphone,Ios,Objective C,Cocos2d Iphone,我在停止行动方面有问题。我有两个精灵动画,一个是蚂蚁,第二个是蚱蜢。当我只是调用ants动画时,它工作得很好,但当我尝试运行ant和grasshopper动画时,它会给我带来错误。 *在-[CCSpriteBatchNode addChild:z:tag:]、/Users/zohaib/Downloads/zohaibgame/zohaibgame/libs/cocoos2d/CCSpriteBatchNode.m:183中断言失败 它在调用antMoveEnded时给出错误 蚂蚁动画代码 -(
-(void) walk_Ants
{
// 1) Cache the sprite frames and texture
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"ant-animation.plist"];
/// 2) Create a sprite batch node
CCSpriteBatchNode *spriteSheet_ant = [CCSpriteBatchNode
batchNodeWithFile:@"ant-animation.png"];
[self addChild:spriteSheet_ant];
// 3rd Step
// 3) Gather the list of frames
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 24; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%d.png", i]]];
}
// 4th Step
// 4) Create the animation object
CCAnimation *walkAnim = [CCAnimation
animationWithSpriteFrames:walkAnimFrames delay:0.05f];
// 5th Step
// 5) Create the sprite and run the animation action
self.ants = [CCSprite spriteWithSpriteFrameName:@"1.png"];
_ants.position = ccp(winSize.width, winSize.height/6);
//_ants.position = ccp(459, 16);
self.walkActionAnt = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];
[_ants runAction:_walkActionAnt];
[spriteSheet_ant addChild:_ants];
CCLOG(@"Position %@",NSStringFromCGPoint(_ants.position));
[self walkingAnts];
}
-(void) walkingAnts
{
// 2) Set the desired velocity
float antVelocity = 480.0/10.0;
// 3) Figure out the amount moved in X and Y
CGPoint waking_Path = CGPointMake(X_AXIS_ENDINGPATH, _ants.position.y);
CGPoint moveDifference = ccpSub(waking_Path, _ants.position);
// 4) Figure out the actual length moved
float distanceToMove = ccpLength(moveDifference);
// 5) Figure out how long it will take to move
float moveDuration = distanceToMove / antVelocity;
// 7) Run the appropriate actions
//[_ants stopAction:_moveAction];
id restartAntWalk = [CCCallFuncN actionWithTarget:self selector:@selector(antMoveEnded:)];
self.moveActionAnt = [CCSequence actions:
[CCMoveTo actionWithDuration:moveDuration position:waking_Path],
restartAntWalk,
nil];
//self.moveActionAnt.tag = 121;
[_ants runAction:_moveActionAnt];
_movingAnt = TRUE;
}
- (void) antMoveEnded: (ccTime) dt
{
if(_ants.position.x == -50)
{
[_ants stopAction:_moveActionAnt];
//[self stopActionByTag:121];
_movingAnt = FALSE;
[self walk_Ants];
}
}
-(void) mantisCome
{
float w_index = arc4random() % 480;
//float h_index = arc4random() % 320;
self.moveActionMantis = [CCSequence actions:
[CCMoveTo actionWithDuration:2 position:ccp(w_index, 63)],
nil];
[_mantis runAction:_moveActionMantis];
[self schedule:@selector(timer:) interval:5];
}
-(void) mantisGo
{
self.moveActionMantis = [CCSequence actions:
[CCMoveTo actionWithDuration:2 position:ccp(-50, 280)],
nil];
[_mantis runAction:_moveActionMantis];
[self unschedule:@selector(timer:)];
[self mantisAnimation];
}
#pragma -mark Mantis Animation
-(void) mantisAnimation
{
// 1) Cache the sprite frames and texture
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"mantis-animation.plist"];
/// 2) Create a sprite batch node
CCSpriteBatchNode *spriteSheet_mantis = [CCSpriteBatchNode
batchNodeWithFile:@"mantis-animation.png"];
[self addChild:spriteSheet_mantis];
// 3rd Step
// 3) Gather the list of frames
NSMutableArray *walkAnimFrames_mantis = [NSMutableArray array];
for(int i = 1; i <= 14; ++i) {
[walkAnimFrames_mantis addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%d.png", i]]];
}
// 4th Step
// 4) Create the animation object
CCAnimation *walkAnim_mantis = [CCAnimation
animationWithSpriteFrames:walkAnimFrames_mantis delay:0.05f];
// 5th Step
// 5) Create the sprite and run the animation action
self.mantis = [CCSprite spriteWithSpriteFrameName:@"1.png"];
_mantis.position = ccp(winSize.width+100, winSize.height+100);
_mantis.flipX=YES;
//_mantis.position = ccp(459, 16);
self.walkActionMantis = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim_mantis]];
walkAnim_mantis.restoreOriginalFrame = NO;
[_mantis runAction:_walkActionMantis];
[spriteSheet_mantis addChild:_mantis];
//CCLOG(@"Position %@",NSStringFromCGPoint(_mantis.position));
[self mantisCome];
}
-(无效)步行者
{
//1)缓存精灵帧和纹理
[[CCSpriteFrameCache sharedSpriteFrameCache]添加SpriteFrameSwithFile:
@“ant animation.plist”];
///2)创建一个sprite批处理节点
CCSpriteBatchNode*spriteSheet_ant=[CCSpriteBatchNode
batchNodeWithFile:@“ant animation.png”];
[self-addChild:spriteSheet_ant];
//第三步
//3)收集帧列表
NSMutableArray*walkAnimFrames=[NSMutableArray];
对于(inti=1;i我找出了问题所在。
当我为ant创建动画时,我使用了以下代码
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 24; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%d.png", i]]];
}
self.ants = [CCSprite spriteWithSpriteFrameName:@"1.png"];
NSMutableArray*walkAnimFrames=[NSMutableArray];
对于(int i=1;i
NSMutableArray *walkAnimFrames_mantis = [NSMutableArray array];
for(int i = 1; i <= 14; ++i) {
[walkAnimFrames_mantis addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%d.png", i]]];
}
self.mantis = [CCSprite spriteWithSpriteFrameName:@"1.png"];