Some basic but pertinent questions about sprites

Yes my questions are basic, but I hunted high and low for some answers before turning here.

I have an app that loads a remote image and uses it as a sprite sheet. This works wonderfully.
From time to time this image is updated, and I need to reload the image and play it back. I have some questions about the best way to do this.

First:
When exactly is the image loaded? Does this happen upon creation of the sprite sheet or does it happen at prepare() or add()? I ask, because if the image is updated in the file system then all I really need to do is reload it - in theory.

Second:
If I can’t do it that way then do I need to actually dispose() my sprite sheet every time I reload it? This also removes the attendant sprite according to the docs. So what I need to do is actually create a whole new sprite, move it up the display list to cover the old one and then call dispose? Is that right?

Is there a recommended way to do something like this?

[import]uid: 11419 topic_id: 20834 reply_id: 320834[/import]

I believe it is at the creation of the sprite sheet, although I need to confirm that.

I would think that the safest way would be to dispose and recreate - it would remove the sprite on screen but if these events are side by side no one looking would see the sprite disappear/reappear, it would be seamless.

Someone else may have other suggestions :slight_smile:

Peach [import]uid: 52491 topic_id: 20834 reply_id: 82142[/import]

Thanks Peach,

I was afraid that might be the answer, though I’d love to know for sure about the moment of load.

I read somewhere that disposing a spritesheet and then recreating it immediately (presumably under the same variable name) could cause problems, so another vote for my theory of two sprites.

In truth two sprites is not such a terrible thing, but it seems needlessly complicated.

[import]uid: 11419 topic_id: 20834 reply_id: 82218[/import]

Hi. It gets loaded upon creation/initialization.

You would need to dispose then recreate

Something like this would handle it nicely

  
local mySheet = nil  
  
local function createSheet()  
 if mySheet ~= nil then  
 mySheet:dispose()  
 mySheet = nil  
 else  
 mySheet = sprite.newSpriteSheetFromData("sheet.png", require("sheet").getSpriteSheetData())  
 end  
end  

[import]uid: 84637 topic_id: 20834 reply_id: 82446[/import]