【问题标题】:CCMotionStreak working with CCMoveToCCMotionStreak 与 CCMoveTo 合作
【发布时间】: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


【解决方案1】:

我怀疑这是一个时间错误。如果序列如下所示,您的 CCMotionStreak 将始终有点偏离:

  1. [streak setPosition:self.theHero.heroSprite.position] -- Streak 在英雄的位置
  2. [CCMoveTo actionWithDuration:du ... -- 英雄出招
  3. 渲染,但英雄和连胜在不同的位置

当你停止移动时,它们会均衡。

我建议在 Hero 类中更新动作连续性,或者使用调度程序设置优先级,以便在 CCMoveTo 动作更新以移动 Hero 之后发生 [streak setPosition 调用。

很可能,第一步的优先级正确且有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多