[英]Phaser - How to change the sprite image of a group?
I'm using Phaser io我正在使用 Phaser io
I'm making a simple game where the player has to avoid falling enemies (objects).我正在制作一个简单的游戏,玩家必须避免掉落的敌人(物体)。 The enemies are created like this:
敌人是这样创建的:
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
})
I know that you can change the sprite image using:我知道您可以使用以下方法更改精灵图像:
player.setTexture('image');
So I tried this:所以我尝试了这个:
enemies.setTexture('image');
But this doesn't work.但这不起作用。
Any ideas?有任何想法吗?
You need to iterate through each item in the group and set the texture on the individual item.您需要遍历组中的每个项目并在单个项目上设置纹理。
enemies.children.iterate((child) => {
child.setTexture('image');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.