admin管理员组文章数量:1022982
In my Phaser game, I want to use a cell-like background texture which moves when you move.
My idea was to add each cell in a for loop like this:
let width=100, height=100;
for(let y=0;y<width;y++){
;
for(let x=0; x<height;x++){
this.physics.add.image(width/2+64*x, height/2+64*y, "snow_field").setScale(4,4);
}
}
The problem: The game gets very (very) slow
So is there a better / remended way to add repeating images/backgrounds?
In my Phaser game, I want to use a cell-like background texture which moves when you move.
My idea was to add each cell in a for loop like this:
let width=100, height=100;
for(let y=0;y<width;y++){
;
for(let x=0; x<height;x++){
this.physics.add.image(width/2+64*x, height/2+64*y, "snow_field").setScale(4,4);
}
}
The problem: The game gets very (very) slow
So is there a better / remended way to add repeating images/backgrounds?
Share Improve this question asked Dec 14, 2021 at 19:55 MoPaMoMoPaMo 6848 silver badges27 bronze badges1 Answer
Reset to default 7You are looking for the Phaser.GameObjects.TileSprite
(link to the documentation)
...
A TileSprite is a Sprite that has a repeating texture.
...
this.add.tileSprite(posX, posY, width, height, "snow_field");
here is a small official example, where you can see it in action.
In my Phaser game, I want to use a cell-like background texture which moves when you move.
My idea was to add each cell in a for loop like this:
let width=100, height=100;
for(let y=0;y<width;y++){
;
for(let x=0; x<height;x++){
this.physics.add.image(width/2+64*x, height/2+64*y, "snow_field").setScale(4,4);
}
}
The problem: The game gets very (very) slow
So is there a better / remended way to add repeating images/backgrounds?
In my Phaser game, I want to use a cell-like background texture which moves when you move.
My idea was to add each cell in a for loop like this:
let width=100, height=100;
for(let y=0;y<width;y++){
;
for(let x=0; x<height;x++){
this.physics.add.image(width/2+64*x, height/2+64*y, "snow_field").setScale(4,4);
}
}
The problem: The game gets very (very) slow
So is there a better / remended way to add repeating images/backgrounds?
Share Improve this question asked Dec 14, 2021 at 19:55 MoPaMoMoPaMo 6848 silver badges27 bronze badges1 Answer
Reset to default 7You are looking for the Phaser.GameObjects.TileSprite
(link to the documentation)
...
A TileSprite is a Sprite that has a repeating texture.
...
this.add.tileSprite(posX, posY, width, height, "snow_field");
here is a small official example, where you can see it in action.
本文标签: javascriptHow do you add repeating images in PhaserStack Overflow
版权声明:本文标题:javascript - How do you add repeating images in Phaser? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745504573a2153546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论