【问题标题】:Cocos2d if statement logic not workingCocos2d if 语句逻辑不工作
【发布时间】:2012-07-05 18:59:05
【问题描述】:

if 语句是: //these x & y do not affect the if statement they are used for the result 6 lines down. int x = enemy.position.x; int y = enemy.position.y; NSLog(@"%G,%G", leftJoystick.velocity.x, leftJoystick.velocity.y);

if ((leftJoystick.stickPosition.x < 1 && leftJoystick.stickPosition.x > -1)&& leftJoystick.stickPosition.y > 0) {
    enemy.position = ccp(x,y-1);
    NSLog(@"North");
    return;
}

在反馈中,它显示-0.0544645,0.998516 有效并且它记录了北,但-0.0725357,0.997366 无效。我不明白为什么?

我正在尝试在 cocos2d 中执行此操作。

【问题讨论】:

  • 为什么在调用“ccp”函数时希望“int”值(对于 x 和 y)保持浮点精度,或者我可能误解了这个问题?跨度>
  • 不同的问题。如果要向北,也就是垂直(Y轴)方向,为什么还要关心摇杆在水平方向(X轴)的位置呢?检查 X 轴是否在 -1 到 1 范围内看起来是多余的,这有什么用?
  • 区分北、东北、西北...
  • @Michael Dautermann int x & y 仅用于玩家的定位问题出在 leftJoystick.stickPosition.x & y
  • 您正在记录速度,但您的逻辑在位置上运行。把它弄清楚,也许答案会更清楚。

标签: iphone if-statement cocos2d-iphone logic


【解决方案1】:

您正在记录速度,但您的逻辑在位置上运行。把它弄清楚,也许答案会更清楚。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    相关资源
    最近更新 更多