norcrel Posted March 27, 2015 Share Posted March 27, 2015 Hello I ran into a problem where each time I spawned a new sprite, the game would lag significantly even though the sprite's texture should already be loaded. I looked into phaser and found this was because the texture, though shared, was always marked dirty when a new sprite was created. There was the workaround of pre-instantiating all the sprites I might need before launching a scene, but I found this to be unscalable since we'd have to guesstimate how many sprites we needed as design changed. I instead made changes to Phaser.Component.LoadTexture.prototype.loadTexture and removed these lines:if (!isRenderTexture){ this.texture.baseTexture.dirty();}This sounded like a reasonable change to make since, if I'm reading the code correctly, base textures are instantiated as dirty to begin with. This means that there's no reason to re-draw the texture. Of course, I don't know the phaser code base as well as the developers here, so I'm wondering if anyone could give me a quick review if this is a reasonable change to make? Thanks! Link to comment Share on other sites More sharing options...
rich Posted March 27, 2015 Share Posted March 27, 2015 You know, you're absolutely right. It's not quite as simple as commenting that line out though - because it's entirely possible for a texture to become dirty via other means. But this has given me some food for thought, so I'll definitely see about doing something to resolve this, or guard against it, in the next release. It's of course only relevant to WebGL too, Canvas isn't effected. Link to comment Share on other sites More sharing options...
norcrel Posted March 27, 2015 Author Share Posted March 27, 2015 I see. What you said about WebGL vs. Canvas would explain why some of my teammates reported the lag missing on certain devices (where I'm guessing they were using Canvas). I'll keep an eye out for any visual bugs that might pop up, but it seems ok for now. Looking forward to the next release Thanks for your help, rich! Link to comment Share on other sites More sharing options...
Recommended Posts