有什么方法可以使用 RunAction 发送 2 个参数?
您会看到我试图移动顶部带有标签的精灵,并且我为每个精灵制作了单独的功能。与此类似。
[sprite runAction:
[CCSequence actions:actionMove, actionMoveDone, nil]];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteLabelMoveFinished:)];
现在,我有 2 个问题,1-有没有办法发送 2 个或更多参数????2-我想知道是否有任何方法可以节省一些内存并通过一个动作来完成?
- (void) spriteMoveFinished:(id)sender
{
CCLOG(@"Sprite move finished");
Sprites *sprite = (Sprites *)sender;
[self animateSprite:sprite];
}
- (void) animateSprite:(Sprites *)zprite
{
CCLOG(@"We're animating sprite"):
Sprites *sprite = nil;
sprite = zprite;
int actualDuration = sprite.speed; //property of sprite
// Create the actions
id actionMove = [CCMoveBy actionWithDuration:actualDuration
position:ccpMult(ccpNormalize(ccpSub(_player.position,sprite.position)), 10)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteMoveFinished:)];
[sprite runAction:
[CCSequence actions:actionMove, actionMoveDone, nil]];
}
- (void) spriteLabelMoveFinished:(CCLabelTTF *)sender
{
[self animateSpriteLabel:sender];
}
-(void)animateEnemyHP:(CCLabelTTF *)zpriteLabel
{
CCLabelTTF *spriteLabel = nil;
spriteLabel = zpriteLabel;
int actualDuration = spriteSpeed; //another property
id actionMove = [CCMoveBy actionWithDuration:actualDuration
position:ccpMult(ccpNormalize(ccpSub(_player.position,spriteLabel.position)), 10)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteLabelMoveFinished:)];
[spriteLabel runAction:
[CCSequence actions:actionMove, actionMoveDone, nil]];
}
现在,这4个功能有点明显。
1-Move Sprite 如果精灵结束移动,我们再次移动它。2-以相同的速度将标签移向相同的位置,如果标签移动完毕,我们再次移动它。
他们都去同一个地方。有没有办法将这 4 个功能混合为 2 个?如果是这样,我如何在动作完成时发送 2 个参数?感谢您的帮助和时间,祝您有美好的一天!