Sprite could not be created since the sprite buffer is full (128). See 'sprite.max_count' in game.project

I am still doing my klondike game and I am working on the stock button
the problem is that when i create all the cards from the stock I am not able to destroy the ones that are hidden.
my sprite buffer is getting full.
please try testing my game in the repo below

press the stock button on the upper left like 30 times and you will get the error
please help.

Your current code only disables the card sprites instead of deleting them. Just change the cards’ self_destruct() function from:

function self_destruct(self)
  -- go.delete({go.get_id(".")}, true)

  -- TODO delete the card

  msg.post("back#back_sprite", "disable")
  msg.post("face#face_sprite", "disable")
  msg.post("#collisionobject", "disable")

end

to:

function self_destruct(self)
   go.delete(".", true)
end
3 Likes

Note that you can also increase the sprite buffer in game.project: Defold project settings

Thank you for your reply.
I also have a rendering problem when spawning cards from the stock button.
how can I make sure that the last card is always rendered on top?
sometimes the cards are not being rendered on top of each other in the right sequence?

You set that using the z component of the object position:

You can change the Z position of objects to control the order they’re rendered in. A higher Z position means it will be rendered on top of an object with a lower Z position.

Keep in mind that objects with a Z position outside of the near/far range will be invisible. In your project, that range is set as -20 to 20.

1 Like