0

我有一个正在接受位置动画的 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

我有什么办法可以做到这一点?

4

1 回答 1

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你的场景范围访问),并用它做任何你需要的事情。

于 2013-08-29T14:56:06.327 回答