简体   繁体   English

如何在 Phaser 中添加重复图像?

[英]How do you add repeating images in Phaser?

In my Phaser game, I want to use a cell-like background texture which moves when you move.在我的 Phaser 游戏中,我想使用一个类似单元格的背景纹理,当你移动时它会移动。

My idea was to add each cell in a for loop like this:我的想法是在 for 循环中添加每个单元格,如下所示:

  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 / recommended way to add repeating images/backgrounds?那么有没有更好/推荐的方法来添加重复的图像/背景?

You are looking for: Phaser.GameObjects.TileSprite ( link to the documentation )您正在寻找:Phaser.GameObjects.TileSprite( 文档链接

... ...
A TileSprite is a Sprite that has a repeating texture. TileSprite 是具有重复纹理的 Sprite。
... ...

this.add.tileSprite(posX, posY, width, height, "snow_field");

here is an small example on phaser.io , where you can see it in action.这是有关 phaser.io 的一个小示例,您可以在其中看到它的运行情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM