我目前正在开发一款使用enchant.js作为游戏引擎的游戏,我正在尝试让玩家的精灵和敌人的精灵发生碰撞,敌人的精灵就会被移除,检测到碰撞的代码就不会再执行了。问题是在删除敌对子画面之后,代码仍然在执行。这是一个web服务器上的游戏。如果你打开控制台,你可以看到它在敌人被移除后发出垃圾邮件“点击”(如果你停留在敌人之前所在的地方)。http://people.ucsc.edu/~kcilia/dainty_knight/
//Executes code every frame
game.addEventListener('enterframe', function() {
//detects whether player sprite is within 40
//pixels of the enemy sprite
if(knight.within(enemy,40)){
//prints "hit" if collision is successful
console.log("hit");
//removes enemy sprite if collision is successful
scene.removeChild(enemy);
}
});发布于 2015-02-27 23:19:24
我有一个类似的问题,但是将敌人归入一个类,并将内部/交叉点侦听器+移除加到敌人身上,它起作用了。
https://stackoverflow.com/questions/21716764
复制相似问题