2017-08-10 8 views
0

私は宇宙船の移動を避けなければならないphaser.jsにゲームを書いています。マウスはUFOで置き換えられます。私は、フェイザーがなぜUFOと宇宙船グループの衝突を検出しないのか理解しようとする助けが必要です。私が潜在的な解決策をたくさん試したので、乱雑さを許してください。 コード:フェイザーは衝突を検出しません

var spaceShip; 
 
var score = 0; 
 
var text; 
 
var gameOver = false; 
 
var veggies; 
 
var cursor; 
 
var gameplayState = { 
 
    create: function() { 
 
     game.add.sprite(0,0,'Stars'); 
 
     veggies = game.add.group(); 
 
     veggies.enableBody = true; 
 
     veggies.physicsBodyType = Phaser.Physics.ARCADE; 
 
     function doSpaceship() { 
 
      
 
      if (ships == true){ 
 
       if (ships == false){ 
 
        kill(); 
 
       } 
 
      if (Math.random() > 0.5){ 
 
       spaceShip = veggies.create(0, 300, 'Ship'); 
 
       spaceShip.angle = 90; 
 
       game.physics.arcade.collide(veggies, cursor, collisionHandler); 
 
       spaceShip.body.velocity.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); 
 
      } else { 
 
       spaceShip = veggies.create(Math.random() * 640, 480, 'Ship'); 
 
       game.physics.arcade.collide(veggies, cursor, collisionHandler); 
 

 
       spaceShip.body.velocity.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); 
 
      } 
 
      } 
 
      function kill(){ 
 
       if(gameOver == false){ 
 
        score++; 
 
       } 
 
       spaceShip.destroy(); 
 
      } 
 
     } 
 
     cursor = game.add.sprite(0,0,'Ufo'); 
 
     var ships = true; 
 
     text = game.add.text(0,0,"Score: " + score); 
 
     text.font = 'Saira Extra Condensed'; 
 
     doSpaceship(); 
 
     function collisionHandler(){ 
 
      gameOver = true; 
 
     } 
 
    }, 
 
    update: function(){ 
 
     cursor.x = game.input.mousePointer.x; 
 

 
     cursor.y = game.input.mousePointer.y; 
 
     text.setText("Score: " + score); 
 
    } 
 
};

答えて

2

あなたは更新機能にライン

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

を移動する必要があります。

関連する問題