cocos2d 警惕 stopAllActions 出错 陷阱 解决办法

当加载的sprite 很多的时候,每个sprite都有N多个action

有一些是序列动作

如下

 CCMoveBy *move = [CCMoveTo actionWithDuration:_moveDuration position:_pullupPoint.point ];
            CCCallFunc* callback = [CCCallFunc actionWithTarget:self selector:@selector(action_Move_PullUp_CallBack_Function:)];
            [callback setTag:999];
            action_Move= [CCSequence actions:move, callback, nil];
            [self runAction:action_Move ];

cocos2d  在执行方法 stopAllActions 时候,,会报错,


报错的原因是没有加 tag 值

这种情况只有在频烦的开始和 stop action 的时候出现,,,解决办法


对每个action  加tag


      下面的方式在特殊情况在会出错(执行stopAllActions出错)

           CCMoveBy *move = [CCMoveTo actionWithDuration:_moveDuration position:_pullupPoint.point ];
            CCCallFunc* callback = [CCCallFunc actionWithTarget:self selector:@selector(action_Move_PullUp_CallBack_Function:)];
        
            [self runAction:[CCSequence actions:move, callback, nil]; ];

改成以下方法



            CCMoveBy *move = [CCMoveTo actionWithDuration:_moveDuration position:_pullupPoint.point ];
            [move setTag:999];
            CCCallFunc* callback = [CCCallFunc actionWithTarget:self selector:@selector(action_Move_PullUp_CallBack_Function:)];
            [callback setTag:999];

 id  action_Move= [CCSequence actions:move, callback, nil];

 [action_Move setTag:999];

            [self runAction:action_Move ];




你可能感兴趣的:(cocos2d)