charlieRobinson Posted January 6, 2017 Share Posted January 6, 2017 Hey, coders! I have the server creating random drops to the client. It creates 5px x 5px squares on the client that the player can walk over and ' pick up'. These sprite drops triggered from server have no physics. they are just squares being stamped on the canvas. When the player walks over one the server removes it and updates the clients. Works fine. Problem is, once 100 or so are made, FPS drops to single digits and everyone slows to molasses. Is there a max sprite count? I do not believe I have any memory leaks and the sprites arent using any physics. Any ideas? Thank you Code to make the square sprites : var bmd = game.add.bitmapData(0,0); bmd.ctx.beginPath(); bmd.ctx.rect(0,0,5,5); bmd.ctx.fillStyle = '#000000'; bmd.ctx.fill(); bmd.ctx.closePath(); var droppedItem = game.add.sprite(xDrop,yDrop, bmd); Link to comment Share on other sites More sharing options...
PhasedEvolution Posted January 6, 2017 Share Posted January 6, 2017 Hmm I think there is something strange in there. I mean you probably figured that out already but I wouldn't say that is "normal". That shouldn't be that heavy. Maybe you are generating more sprites than you think you are? Link to comment Share on other sites More sharing options...
Fatalist Posted January 6, 2017 Share Posted January 6, 2017 You are creating a new texture for each sprite. Lots of textures = lots of draw calls. Create only one texture and let the sprites share it. var bmd = game.add.bitmapData(width, height); bmd.ctx.beginPath(); bmd.ctx.rect(0,0,5,5); bmd.ctx.fillStyle = '#000000'; bmd.ctx.fill(); bmd.ctx.closePath(); .... var droppedItem1 = game.add.sprite(xDrop1,yDrop1, bmd); var droppedItem2 = game.add.sprite(xDrop2,yDrop2, bmd); var droppedItem3 = game.add.sprite(xDrop3,yDrop3, bmd); ..... --------------------- "add.bitmapData(0,0);" I assume it's not 0,0 it the real code, right? PhasedEvolution 1 Link to comment Share on other sites More sharing options...
charlieRobinson Posted January 9, 2017 Author Share Posted January 9, 2017 On 1/6/2017 at 5:54 PM, Fatalist said: You are creating a new texture for each sprite. Lots of textures = lots of draw calls. Create only one texture and let the sprites share it. var bmd = game.add.bitmapData(width, height); bmd.ctx.beginPath(); bmd.ctx.rect(0,0,5,5); bmd.ctx.fillStyle = '#000000'; bmd.ctx.fill(); bmd.ctx.closePath(); .... var droppedItem1 = game.add.sprite(xDrop1,yDrop1, bmd); var droppedItem2 = game.add.sprite(xDrop2,yDrop2, bmd); var droppedItem3 = game.add.sprite(xDrop3,yDrop3, bmd); ..... --------------------- "add.bitmapData(0,0);" I assume it's not 0,0 it the real code, right? !!! Man, that was it! Thank you!!! Im such a n00b! Fatalist 1 Link to comment Share on other sites More sharing options...
Recommended Posts