【问题标题】:How do you add repeating images in Phaser?如何在 Phaser 中添加重复图像?
【发布时间】:2022-01-18 02:48:37
【问题描述】:

在我的 Phaser 游戏中,我想使用一个类似单元格的背景纹理,它会随着你的移动而移动。

我的想法是像这样在 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);
      
    }
  }

问题:游戏变得非常(非常)慢

那么有没有更好/推荐的方法来添加重复的图像/背景?

【问题讨论】:

    标签: javascript html phaser-framework


    【解决方案1】:

    您正在寻找:Phaser.GameObjects.TileSprite (link to the documentation)

    ...
    TileSprite 是具有重复纹理的 Sprite。
    ...

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

    这是一个小的example on phaser.io,您可以在其中看到它的运行情况。

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 1970-01-01
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      相关资源
      最近更新 更多