Hello. I’m trying to fix lags (on video). I’ve tried many options(create pool of platforms, recycling platforms), nothing helps me. Can you help with advice? Thanks
Video - https://streamable.com/gyrueo
Creating platforms:
platform = this.add.tileSprite(posX, posY, platformWidth, 72, "block"); platform.setOrigin(0, 0.5); this.physics.add.existing(platform); platform.body.setImmovable(true); platform.body.setVelocityX(this.gameOptions.platformSpeed); platform.setDepth(2); this.lastAddedPlatform = platform; this.platformGroup.add(platform);
Remove platforms in update:
this.platformGroup.getChildren().forEach((platform) => { if (platform.x + platform.width <= 0) { this.platformGroup.killAndHide(platform); this.platformGroup.remove(platform); } }, this);
Is there a reason you’re using a tileSprite? I only ask because they don’t batch in WebGL, where-as Sprites do. Also, what value is platformWidth
?
Thanks for the answer. I use tileSprite because I saw this way in examples. platformWidth is random number between 576 and 960. Is it better to use sprites? This problem may occur on the sprite size?Thank you.
Basically TileSprites don’t batch very well (at all, really), so if you can use Sprites it’d be much better. You could just create a nice long texture and then use the ‘crop’ feature to make it visually shorter, that would be one way I guess. Perhaps, for now, just replace the tileSprites with a this.add.rectangle
instead? At least it will confirm, one way or another, if that really is the cause.