Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在cocos2d中获取发送方对象_Iphone_Objective C_Xcode_Cocos2d Iphone_Ccsprite - Fatal编程技术网

Iphone 在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

我正在用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];
    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动画不工作?