我正在尝试使用 CCMotionStreak 用 CCSprite 绘制路径。
在里面:
CCMotionStreak* streak;
streak = [CCMotionStreak streakWithFade:100 minSeg:1 image:@"streak.png" width:5
length:3 color:ccc4(0, 255, 255, 255)];streak.position = self.theHero.heroSprite.position;
当触摸结束时:
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
{
[self unschedule:@selector(doStep:)];
CGPoint touchLocation = [touch locationInView: [touch view]];
CGPoint curPosition = [[CCDirector sharedDirector] convertToGL:touchLocation];
[self.theHero.heroSprite stopAllActions];
//cal the duration, speed is set to 85.0f
float du = ccpDistance(self.theHero.heroSprite.position, curPosition) / 85.0f;
[self.theHero.heroSprite runAction:[CCMoveTo actionWithDuration:du
position:curPosition]];
[self schedule:@selector(doStep:)];
}
- (void)doStep:(ccTime)delta
{
//update the position
[streak setPosition:self.theHero.heroSprite.position];
}
当我运行演示时,CCMotionStreak 第一次画得很漂亮
我触摸了屏幕,然后当 Sprite 停止时,我试图触摸其他地方
在屏幕上,CCMotionStreak 成功绘制了第二条线,但我注意到
CCMotionStreak 线在 Sprite 移动期间“摇晃”一点(偏移一点),然后在 Sprite 停止移动时“摇回正常位置”。
希望有人能指点一下,谢谢:)
最佳答案
我怀疑这是一个时间错误。如果序列如下所示,您的 CCMotionStreak 将始终有点偏离:
[streak setPosition:self.theHero.heroSprite.position]
-- Streak 处于英雄位置 [CCMoveTo actionWithDuration:du ...
-- 英雄招式当你停止移动时,它们相等。
我建议更新 Hero 类中的连续运动,或使用调度程序设置优先级,以便
[streak setPosition
调用发生在 CCMoveTo
之后 Action 更新以移动英雄。很可能,第一步的优先级是正确的,而且是有效的。
关于cocos2d-iphone - CCMotionStreak 与 CCMoveTo 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921825/