简体   繁体   English

Phaser是否渲染可见设置为false的精灵?

[英]Does Phaser render sprites with visible set to false?

Does Phaser render sprites with visible set to false? Phaser是否渲染可见设置为false的精灵?

I'm making a game much like Motherload but with infinite terrain. 我制作的游戏非常类似于Motherload,但是地形无限。 The terrain generates as you go along and is made of 64x64 sized sprites (tiles), as you can imagine as you go along alot of sprites are added to the scene. 地形生成,当您去,并且由64×64大小的小精灵(砖),你可以想像,当您很多的精灵被添加到场景中去。 Sprites which go out of view have their visible property set to false however my frame rate (FPS) drops considerably as the player goes along and alot of terrain is generated. 精灵其出门的观点有其Visible属性设置为false,但是我的帧率(FPS)的玩家一起去,并生成地形的很多显着下降。 Why is this if only the sprites on screen have their visible property set to true? 如果仅将屏幕上的精灵的可见属性设置为true,为什么会这样? I have checked over and over again that only the sprites on screen have their visible property set to true and don't understand why my FPS drops so much as I go along, is Phaser still rendering these sprites with visible set to false? 我已经一遍又一遍地检查,只有屏幕上的精灵将其可见属性设置为true,并且不明白为什么我的FPS随我的下落而下降很多,Phaser是否仍将这些可见设置为false的精灵渲染?

Instead of constantly creating new Sprites and then .kill() ing them, you should be recycling Sprites. 而不是不断创建新的Sprites然后.kill()处理,应该回收Sprites。

Here's an example on Recycling. 这是有关回收的示例

It's the same technique used in Particle Effects (so that if a particle generator runs for infinity, it only creates a finite number of particles) 这与“粒子效果”中使用的技术相同(因此,如果粒子生成器运行到无穷远,它将仅创建有限数量的粒子)

Here's the steps to use: 使用步骤如下:

  1. Create a number of sprites (probably 2x the size of your screen) in a Phaser.Group Phaser.Group创建许多精灵(可能是屏幕大小的2 Phaser.Group
  2. render the initial scene (position, image) for each sprite 渲染每个精灵的初始场景(位置,图像)
  3. As a sprite moves off-screen (check in update using sprite.inCamera ) then .kill() it. 当精灵移出屏幕(使用sprite.inCamera检查update ),然后.kill()
  4. When it's time to draw a new sprite on the screen, use getFirstExists(false) to get a re-used sprite that's not visible . 当需要在屏幕上绘制新的精灵时,请使用getFirstExists(false)获取不可见的已重用的精灵。
  5. update the sprite's image and position 更新精灵的图像和位置
  6. tell the game to render the sprite using .revive() 告诉游戏使用.revive()渲染精灵

And voila! 瞧! You'll see a massive performance increase. 您会看到巨大的性能提升。 (especially if you were trying to create 1,000s of sprites before) (尤其是如果您之前尝试创建1,000个精灵,则尤其如此)

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

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