2013-04-05 59 views
0

我正在使用cocos2d製作遊戲。通過使用以下代碼,我添加了一個動畫。如何發送CCSprite參考?在cocos2d中獲取發件人對象

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_sprite方法中的精靈參考?

+1

讓精靈伊娃,或給它一個標籤和使用getchildbytag – LearnCocos2D 2013-04-05 06:44:04

回答

1

您可以使用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對象,因爲你根本沒有使用它。

+0

感謝您reply.But如何讓精靈對象animate_sprite方法? – Madhumitha 2013-04-05 06:51:37

+0

我已經更新了我的回答 – btype 2013-04-05 06:56:35

+0

它正在從init方法調用時工作。但是當我調用from-(void)update:(ccTime)dt時,此方法動畫無法正常工作。從CCtime動畫將無法工作? – Madhumitha 2013-04-05 07:05:33

相關問題