【问题标题】:Phaser - How to change the sprite image of a group?Phaser - 如何更改组的精灵图像?
【发布时间】:2019-10-14 18:32:43
【问题描述】:

我正在使用 Phaser io

我正在制作一个简单的游戏,玩家必须避免掉落的敌人(物体)。敌人是这样创建的:

    const enemies = this.physics.add.group();
    function enemyGen(){
      const xCoord = Math.random()*gameState.w;
      enemies.create(xCoord, 10, 'enemy').setScale(0.4);
    }
    const enemyGenLoop = this.time.addEvent({
      callback: enemyGen,
      delay: 800,
      callbackScope: this,
      loop: true
    })

我知道您可以使用以下方法更改精灵图像:

player.setTexture('image');

所以我尝试了这个:

enemies.setTexture('image');

但这不起作用。

有什么想法吗?

【问题讨论】:

    标签: javascript phaser-framework


    【解决方案1】:

    您需要遍历组中的每个项目并为单个项目设置纹理。

    enemies.children.iterate((child) => {
      child.setTexture('image');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多