我有一个正在进行位置动画的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
我能做到这一点吗?
答案 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
),并随身携带。