Cocos2s:在到达目的地之前动画时获取CCSprite位置

时间:2013-08-29 14:00:20

标签: ios animation cocos2d-iphone ccsprite

我有一个正在进行位置动画的CCSprite。它完美地动画。 在某个时间点,在开始动画和到达最终位置之间,我想获得CCSprite的确切位置

我知道sprite.position将返回最终位置

这是动画代码:

sprite = [CCSprite spriteWithFile:@"sprite.png"];
[sprite setPosition:ccp(winSize.width/2, 170)];
[self addChild:sprite];

CCMoveTo *moveSpriteUp = [CCMoveTo actionWithDuration:2.0 position:ccp(winSize.width/2, 210)];
CCEaseOut *upEase = [CCEaseOut actionWithAction:moveSpriteUp rate:2];

CCMoveTo *moveSpriteDown = [CCMoveTo actionWithDuration:2.0 position:ccp(winSize.width/2, 170)];
CCEaseOut *downEase = [CCEaseOut actionWithAction:moveSpriteDown rate:2];

CCSequence * spriteMoveSeq = [CCSequence actions:upEase, downEase, nil];
CCRepeatForever *spriteRepeat = [CCRepeatForever actionWithAction:spriteMoveSeq];

[sprite runAction:spriteRepeat]; 
//1 or 1.x seconds later, the sprite's Y postion will be somewhere between 170 and 210, this is what I want to catch

我能做到这一点吗?

1 个答案:

答案 0 :(得分:0)

CCDelayTime + CCCallFunc呢?像.-

之类的东西
CCDelayTime *delay = [CCDelayTime actionWithDuration:kDelay];
CCCallFunc *func = [CCCallFunc actionWithTarget:self selector:@selector(getSpritePosition)];

[sprite runAction:spriteRepeat];
[self runAction:[CCSequence actionOne:delay two:func]];

getSpritePosition中,您可以获得sprite位置(假设可以从您的场景范围访问sprite),并随身携带。