我正在使用iphone 游戏教程ccTouchesEnded
的第二部分,我对该方法的实现感到困惑。这是实现“射击”的地方:玩家(一门大炮)转向接触的方向,射弹被射击。我不清楚的部分是:_nextProjectile
似乎在它仍然可以使用的时候被释放(通过它下面的代码 - _nextProjectile runAction
)。您能否解释一下为什么此时释放该对象是安全的?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[_player runAction:
[CCSequence actions:
[CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
[CCCallBlock actionWithBlock:^{
// OK to add now - rotation is finished!
[self addChild:_nextProjectile];
[_projectiles addObject:_nextProjectile];
// Release
[_nextProjectile release];
_nextProjectile = nil;
}],
nil]];
// Move projectile to actual endpoint
[_nextProjectile runAction:
[CCSequence actions:
[CCMoveTo actionWithDuration:realMoveDuration position:realDest],
[CCCallBlockN actionWithBlock:^(CCNode *node) {
[_projectiles removeObject:node];
[node removeFromParentAndCleanup:YES];
}],
nil]];
}