【发布时间】:2011-05-07 14:56:36
【问题描述】:
我正在尝试使用 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 第一次画出漂亮的线条 我触摸了屏幕,然后当精灵停止时,我试图触摸其他地方 在屏幕上,CCMotionStreak 成功绘制了第二条线,但我注意到 CCMotionStreak 线在精灵移动期间“摇晃”一点(偏移一点),然后在精灵停止移动时“摇回正常位置”。
希望有人能给我指点一下,谢谢:)
【问题讨论】:
-
如果您尝试对连胜应用相同的 moveTo 方法而不是手动更新其位置会怎样?
标签: cocos2d-iphone