Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 移相器无法检测碰撞_Javascript_Phaser Framework - Fatal编程技术网

Javascript 移相器无法检测碰撞

Javascript 移相器无法检测碰撞,javascript,phaser-framework,Javascript,Phaser Framework,我正在用phaser.js编写一个游戏,你必须避免移动太空船。鼠标被不明飞行物取代。我需要帮助来找出为什么phaser不能检测到UFO和宇宙飞船群之间的碰撞。请原谅这些混乱,因为我已经尝试了很多可能的解决方案。 代码: var飞船; var得分=0; var文本; var gameOver=false; 蔬菜; var光标; 变量gameplayState={ 创建:函数(){ game.add.sprite(0,0,'Stars'); veggies=game.add.group(); ve

我正在用phaser.js编写一个游戏,你必须避免移动太空船。鼠标被不明飞行物取代。我需要帮助来找出为什么phaser不能检测到UFO和宇宙飞船群之间的碰撞。请原谅这些混乱,因为我已经尝试了很多可能的解决方案。 代码:

var飞船;
var得分=0;
var文本;
var gameOver=false;
蔬菜;
var光标;
变量gameplayState={
创建:函数(){
game.add.sprite(0,0,'Stars');
veggies=game.add.group();
veggies.enableBody=真;
veggies.physicsBodyType=Phaser.Physics.ARCADE;
函数doSpaceship(){
if(ships==true){
if(ships==false){
杀死();
}
if(Math.random()>0.5){
spaceShip=vegies.create(0,300,'Ship');
宇宙飞船。角度=90;
游戏。物理。街机。碰撞(蔬菜,光标,碰撞处理器);
宇宙飞船。物体。速度。x=1000;
fx.play();
var times=game.time.events.add(Phaser.Timer.SECOND*Math.random()*3,doSpaceship,this);
var timess=game.time.events.add(Phaser.Timer.SECOND*1,kill,this);
}否则{
spaceShip=vegies.create(Math.random()*640480,“Ship”);
游戏。物理。街机。碰撞(蔬菜,光标,碰撞处理器);
宇宙飞船。物体。速度。y=-1000;
gx.play();
var times=game.time.events.add(Phaser.Timer.SECOND*Math.random()*3,doSpaceship,this);
var timess=game.time.events.add(Phaser.Timer.SECOND*1,kill,this);
}
}
函数kill(){
如果(gameOver==false){
分数++;
}
宇宙飞船。摧毁();
}
}
光标=game.add.sprite(0,0,'Ufo');
var=true;
text=game.add.text(0,0,“分数:”+分数);
text.font='Saira额外压缩';
doSpaceship();
函数collisionHandler(){
gameOver=true;
}
},
更新:函数(){
cursor.x=game.input.mousePointer.x;
cursor.y=game.input.mousePointer.y;
text.setText(“分数:+Score”);
}

};您应该移动该行

game.physics.arcade.collide(veggies, cursor, collisionHandler);

到更新功能。

您应该移动该行

game.physics.arcade.collide(veggies, cursor, collisionHandler);
到更新函数