cocos2d-iphone - CCMotionStreak 与 CCMoveTo 一起使用

标签 cocos2d-iphone

我正在尝试使用 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/

    相关文章:

    ios - Cocos2d 和 ios5 : ccTouchesBegan

    iphone - 如何在cocos2d中对多个 Sprite 进行像素完美碰撞?

    iphone - 链接错误重复符号

    iphone - 在动画 Sprite 上添加标签

    ios - 围绕 anchor 旋转 Sprite

    javascript - 有人可以举例说明使用cocos2d javascript端口的音频引擎吗

    cocos2d-iphone - Cocos2D 与新的 RevMobAds 框架

    objective-c - 几个 UIViewController 和 OpenGLView (Cocos2D) 之上的透明 UITableView

    objective-c - IOS应用程序中的虚拟和实际内存

    ios - 如何区分点击和按住?