game.physics.arcade.collide() 在移相器 js 中

game.physics.arcade.collide() in phaser js

我使用 framework phaser js。 我使用 graphics

创建了两个圆圈
var graphics;
var ball;

var graphics1;
var ballHome;

function create(){
  game.physics.startSystem(Phaser.Physics.ARCADE);  

    graphics=game.add.graphics(500,500);    //first circle
    game.physics.arcade.enable(graphics);
    graphics.enableBody=true;
    graphics.beginFill(0xFFFFFF,1);
    ball=graphics.drawCircle(10,10,15);
    graphics.endFill();


    graphics1=game.add.graphics(500,500);   //second circle
    game.physics.arcade.enable(graphics1);
    graphics1.enableBody = true;
    graphics1.beginFill(0xFFF55F,1);
    ballHome=graphics1.drawCircle(300,300,500);
    graphics1.endFill();

}

function update() {
     game.physics.arcade.collide(ball,ballHome); 
}

我要他们碰撞

为什么 game.physics.arcade.collide(ball,ballHome) 不起作用?

感谢您的帮助

问题是collide()函数将Phaser.Sprites作为输入,但ballballHome不是精灵;它们是 PIXI.Graphics 个对象。您需要从 Graphics 对象创建精灵,然后将这些精灵传递到 collide().

要从您的 graphics 对象制作精灵,首先使用您刚刚创建的纹理调用 Graphics.generateTexture() (doc) to create a texture, then call game.add.sprite() (doc)。

有关 Phaser 的更多信息以及大量非常有用的教程,请参阅 Phaser website