我正在使用CCParallaxNode
添加一些具有不同parallaxRatios和z的精灵(云)。当云离开屏幕时,我想从CCParallaxNode
中删除它们。但是当我这样做时,我收到一个错误:
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
The process has been returned to the state before expression evaluation.
当CCParallaxNode
尝试访问其子位置时,{1}}的访问方法会抛出此错误:
-(void) visit
{
CGPoint pos = [self absolutePosition_];
if( ! CGPointEqualToPoint(pos, _lastPosition) ) {
for (CGPointObject *point in _parallaxArray) {
float x = -pos.x + pos.x * point.ratio.x + point.offset.x;
float y = -pos.y + pos.y * point.ratio.y + point.offset.y;
point.child.position = ccp(x,y); //error is thrown here
}
_lastPosition = pos;
}
[super visit];
}
这就是我删除子节点的方法:
[_parallax addChild:cloud z:-z parallaxRatio:ccp(1/(CGFloat)z,0) positionOffset:cloud.position];
CGFloat life = 6;
[cloud runAction:[CCActionSequence actionWithArray:@[[CCActionDelay actionWithDuration:life],[CCActionCallBlock actionWithBlock:^(){
[_parallax removeChild:cloud cleanup:YES];
}]]]];