Iphone 在cocos2d中获取发送方对象
我正在用cocos2d做一个游戏。通过使用以下代码,我添加了一个动画。如何发送Iphone 在cocos2d中获取发送方对象,iphone,objective-c,xcode,cocos2d-iphone,ccsprite,Iphone,Objective C,Xcode,Cocos2d Iphone,Ccsprite,我正在用cocos2d做一个游戏。通过使用以下代码,我添加了一个动画。如何发送CCSprite参考 if(sprite != monkey) { [self scheduleOnce:@selector(animate_sprite:) delay:0.1f]; } -(void)animate_sprite:(ccTime) dt { id s2 = [CCScaleTo actionWithDuration:0.5 scaleX:2.0 scaleY:2.0]; i
CCSprite
参考
if(sprite != monkey)
{
[self scheduleOnce:@selector(animate_sprite:) delay:0.1f];
}
-(void)animate_sprite:(ccTime) dt
{
id s2 = [CCScaleTo actionWithDuration:0.5 scaleX:2.0 scaleY:2.0];
id fun = [CCCallFuncN actionWithTarget:self selector:@selector(spriteDone:)];
[sprite runAction:[CCSequence actions:s2,fun,nil]];
}
如何在
animate\u sprite
方法中获取精灵引用?您可以使用performSelector:withObject:afterDelay
执行同样的操作
if(sprite != monkey)
{
[self performSelector:@selector(animate_sprite:) withObject:sprite afterDelay:0.1f];
}
-(void)animate_sprite:(CCSprite *)sprite
{
id s2 = [CCScaleTo actionWithDuration:0.5 scaleX:2.0 scaleY:2.0];
id fun = [CCCallFuncN actionWithTarget:self selector:@selector(spriteDone:)];
[sprite runAction:[CCSequence actions:s2,fun,nil]];
}
因此,只需编辑您的方法以使用精灵而不是ccTime对象,因为您根本不使用它。将精灵设为ivar,或者给它一个标记并使用GetChildByTag谢谢您的回答。但是如何在animate_sprite方法中获取精灵对象?当我从init方法调用时,它会工作。但是当我从-(void)update:(ccTime)调用时dt此方法动画不工作。从CCtime动画不工作?