简体   繁体   English

一幅带有Alpha滞后Spritekit的图像

[英]One image with alpha lagging spritekit

I am making a game, and it involves a sandstorm. 我正在做一个游戏,其中涉及一场沙尘暴。 I decided that the basic concept would be that I would make an image that looks roughly like a sandstorm, and then decorate it with some particles/whatever else it takes. 我认为基本概念是,我将制作一张看起来像沙尘暴的图像,然后用一些粒子/除其他以外的东西装饰它。

I ran into an issue at step one. 我在第一步中遇到了一个问题。 I threw together a simple image for testing purposes: 我将一个简单的图像放在一起进行测试: 沙尘暴

I added that to my game, and the FPS dropped by 60%. 我将其添加到游戏中,FPS下降了60%。 I was surprised by the effect one image had, but I wasn't too worried about it. 一幅图像的效果让我感到惊讶,但我并不太担心。 I cut the resolution of the image in half, and again, lots of lag. 我将图像的分辨率降低了一半,而且又有很多滞后。

Is spritekit/iOS really that bad at handling moderately sized images with alpha? spritekit / iOS在处理带有Alpha的中等大小的图像时真的不好吗? I read on another question that the simulator is bad at rendering, but that can't be the entire problem. 我读了另一个问题,即模拟器不擅长渲染,但这不能解决整个问题。

Is there any hope for getting this to render without slicing my performance? 是否有希望在不降低性能的情况下呈现此效果? The particles work well, everything else runs at 60fps just fine, but the addition of this image is apparently a severe drain on resources. 粒子效果很好,其他所有东西都以60fps运行就很好了,但是添加此图像显然会严重消耗资源。

EDIT: I tested my game out on my phone, and I got no lag. 编辑:我在手机上测试了我的游戏,我没有任何滞后。 So apparently, the simulator is just really bad at rendering after all. 因此,显然,模拟器毕竟在渲染方面真的很糟糕。 At the same time, I am curious as to how to speed up performance, as there is clearly some kind of lag going on. 同时,我对如何提高性能感到好奇,因为显然存在某种滞后。

I'm no expert on SpriteKit, but I had similar experiences with plain core animation and layering. 我不是SpriteKit的专家,但是我在普通核心动画和分层方面有类似的经验。

The issue is that an image with alpha, even for the "opaque" parts of it, it introduces a redrawing call on all the sublayers underneath it for every time it moves. 问题在于,即使在图像的“不透明”部分中,具有alpha的图像也会在每次移动时在其下面的所有子层上引入重绘调用。 First check if this is actually the problem, and then, try one of this, and see if it improves: 首先检查这是否确实是问题所在,然后尝试其中一个,然后看是否有所改善:

  1. SKCropNode could prevent for rendering the underneath elements SKCropNode可以防止渲染下面的元素
  2. Tile the image so only the border has alpha 平铺图像,以便只有边框具有Alpha
  3. Snapshot the underneath layers. 快照下层。
  4. Reduce the amount of nodes being rendered, hide the ones that are "under the sandstorm". 减少渲染的节点数量,隐藏“在沙尘暴之下”的节点。

And you should be using real devices to test performance of your game, you cannot rely on the simulator for that. 而且您应该使用真实的设备来测试游戏的性能,因此您不能依赖模拟器。

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

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