Removing a sprite created through sol.sprite.create ?

Started by MetalZelda, October 08, 2017, 05:18:54 PM

Previous topic - Next topic
October 08, 2017, 05:18:54 PM Last Edit: October 08, 2017, 05:33:36 PM by MetalZelda
Hi

I'm having troubble with cutscenes and sprites management.
I am currently making sage cutscenes with as inspiration ALTTP, but, after a while, the crystal around the sage needs to be removed



The sprite creation is a bit different because the cutscene starts immediately after the boss died, a surface fades to accomplish the black background, a menu handles the whole cutscene (mostly to overwrite and avoid pausing / moving, doing actions during cutscene)

Sprites are created in this order

black surface
Link sprite
Sage sprite
Crystal sprite

All created by sol.surface / sprite.create

But, calling

sprite:remove()

this happen

Error: In timer callback: [string "maps/cutscene_data/SageScene_0.lua"]:95: attempt to call method 'remove' (a nil value)

I can't use map entities because the menu is started above everything on the map, entities are not visible during the cutscene because of the background surface
Which confuse me a bit, we can't remove a sprite ?

entity:remove() removes the entity from the map. That's why sprites have no method remove(): they are not on the map.

If you want to stop displaying a sprite, simply stop calling sprite:draw() in your draw event. A good practice is also to assign nil to the sprite so that its memory gets freed.