【问题标题】:How to move sprite continously between two object如何在两个对象之间连续移动精灵
【发布时间】:2012-08-02 04:45:04
【问题描述】:

我有 3 个精灵 A、B 和 C。

A 和 C 是对象...

B 是敌人的精灵...所以设计如下。我需要 B 在 A 和 C 之间不断移动。

A----------B----------C

我在更新方法中使用以下方法。这样每个帧都会调用方法。

ABcollision
{
if(Aistouched == YES)
{
Bvelocity.x = 5;  /// moves my sprite B right side
}
}

CBcollision
{
if(Cistouched == YES)
{
Bvelocity.x = -5; /// moves my sprite B right side
}
}

我的更新速度的更新方法:

   b2Vec2 dins = dinobody->GetLinearVelocity();
   dinobody->SetLinearVelocity(Bvelocity);

上面的代码让我的精灵B只左右移动一次。

【问题讨论】:

  • 能否提供您的搬家方法的代码?问题可能在于没有上一步。创建一个新的变量名 previousStep 并且每次在使用 Bvelocity 更新您的位置之前,使用 Bvelocity 更新 previousStep,如果发生碰撞,在更改速度之前将 B 向后退一步。
  • 我更新了我的问题..如何在 box2d 中向后移动一步?

标签: ios cocos2d-iphone boolean box2d-iphone


【解决方案1】:

我相信它只工作一次时的问题是因为你从来没有根据我的判断重置你的 BOOL。 AistouchedCistouched。尝试在设置 Bvelocity.x = 5; 之后立即添加 Aistouched = FALSE,对于 C 也是如此。

【讨论】:

    猜你喜欢
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多