Cocos2D - 在标签上运行操作

时间:2013-06-10 15:04:31

标签: cocos2d-iphone label action

我试图为标签生成一个动作,这是一个精灵的属性。

这就是我尝试的但是标签没有移动,我无法确定它们可能导致它们不移动的原因..

    - (void) spriteLabelMoveFinished:(id)sender
    {
CCLOG(@"AnimateLabel Move Finished");
Sprites *sprite = (Sprites *)sender;

CCLOG(@"LabelFinalPosition: %f,%f",sprite.spriteLabel.position.x,sprite.spriteLabel.position.y);
[self animateSpriteLabel:sprite.spriteLabel];

    }


    -(void)animateSpriteLabel:(Sprites *)sprite
    {
CCLOG(@"We're animating the SpriteLabel");

CCLabelTTF *spriteLabel = nil;

spriteLabel = sprite.spriteLabel;


int actualDuration = spriteLabelSpeed; // Another Property, inside the .m

// Create the actions

CCLOG(@"AnimatingLabel LabelPosition: %f,%f",spriteLabel.position.x,spriteLabel.position.y);

id actionMove = [CCMoveBy actionWithDuration:actualDuration
                                    position:ccpMult(ccpNormalize(ccpSub(_player.position,spriteLabel.position)), 10)];

id actionMoveDone = [CCCallFuncN actionWithTarget:self
                                         selector:@selector(spriteLabelMoveFinished:)];
[sprite runAction:
 [CCSequence actions:actionMove, actionMoveDone, nil]];

    }

标签刚出现但不移动.... 感谢您的帮助和时间,请有一个好的!

2 个答案:

答案 0 :(得分:0)

您正在对Sprite对象运行操作,而不是在spriteLabel上。 尝试改变:

[sprite runAction:
    [CCSequence actions:actionMove, actionMoveDone, nil]];

[spriteLabel runAction:
    [CCSequence actions:actionMove, actionMoveDone, nil]];

答案 1 :(得分:0)

该行:

[self animateSpriteLabel:sprite.spriteLabel];

应为:

[self animateSpriteLabel:sprite];

我认为这会产生你想要的结果。我有点惊讶你没有编译器警告/错误。