首页 > 解决方案 > Phaser3 中的随机星星

问题描述

我有一群明星。一开始它只给了我1星。我想做,如果我拿这颗星,它给我 2 颗星,如果我拿 2 颗星,它给我 3 颗星,以此类推。我该怎么做?

stars = this.physics.add.group({
    key: 'star',
    repeat: -1,
    setXY: {
      x: Phaser.Math.RND.between(0, 900),
      y: Phaser.Math.RND.between(0, 600),
      frameQuantity: 2,
      repeat: 5
     }    
});

 this.physics.add.overlap(player, stars, collectStar, null, this);


function collectStar (player,star){
  star.disableBody(true, true);
  score += 2;    // COUNT BY 2
  scoreText.setText('Score: ' + score);
}

标签: javascriptphaser-framework

解决方案


推荐阅读