我的程序遇到了一个奇怪的错误,我似乎无法修复。总而言之,每当我切换两个if语句时,只有第一个语句才会生效。
示例:(球将成功地与顶部碰撞,但不会与底部碰撞。)
ReferenceError: PageType is not defined
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\webpack:\src\data\types\PageType.js:50:1)
at __webpack_require__ (H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:19:1)
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\server.js:731:74)
at __webpack_require__ (H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:19:1)
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\webpack:\src\data\schema.js:1:1)
at __webpack_require__ (H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:19:1)
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\server.js:1098:72)
at __webpack_require__ (H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:19:1)
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\server.js:7455:18)
at __webpack_require__ (H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:19:1)
at H:\Coding\Projects\react-starter-kit\build\webpack:\webpack\bootstrap 8ce5b4572987765a465d:65:1
at Object.<anonymous> (H:\Coding\Projects\react-starter-kit\build\server.js:71:10)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
现在,如果我切换两个if语句的位置,就像这样;
public void update()
{
if(enemies != null)
{
for(Enemy e : enemies)
if(c.getBall().getHitbox().intersects(e.getHitbox()))
{
if(e.collidedBottom())
c.getBall().setSpeedY((c.getBall().ballSpeed));
if(e.collidedTop())
c.getBall().setSpeedY(-(c.getBall().ballSpeed));
deadEnemies.add(e);
}
enemies.removeAll(deadEnemies);
}
球会在与底部碰撞时成功反应,但不会与顶部碰撞。这是两种碰撞方法:
if(e.collidedTop())
c.getBall().setSpeedY(-(c.getBall().ballSpeed));
if(e.collidedBottom())
c.getBall().setSpeedY((c.getBall().ballSpeed));
Enemy指的是循环中当前聚焦的块。