更新时间:2023-02-02 09:30:21
我遇到了同样的问题!问题出在这一行...
I have had the same problem! The issue is in this line...
let element = SKSpriteNode(imageNamed: "obsticle1")
SpriteKit不够聪明,不知道已经使用该图像创建了纹理。所以它正在做的是一遍又一遍地创造这种纹理,这是昂贵的。
SpriteKit isn't smart enough to know that a texture was already created with that image. So what it is doing is creating that texture over and over again and that is expensive.
首先在循环外部创建纹理,然后使用纹理创建精灵节点。这样的东西...
Instead create a texture outside of the loop first and then create the sprite node with a texture. Something like this...
let elementTexture = SKTexture(imageNamed: "objstical1")
for i in 0...300 {
let element = SKSpriteNode(texture: elementTexture)
element.hidden = true
obsticle1Pool.append(element)
}
这不仅会快一点,而且还会减少你的应用程序内存。 。假设我遇到了同样的问题。希望这会有所帮助。
Not only will this be a ton faster it will decrease your apps memory a ton...assuming it was the same issue I was having. Hopefully that helps.