Jump to content

Max Sprite Count Limitations


charlieRobinson
 Share

Recommended Posts

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

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?

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...