I have various newImageRect that change their image dynamically according to settings. But they don’t change if I create them in scene:create, they only change on update when returning to the scene if the images are created in scene:show.
Is there any point in this case in creating them in both show and hide?
Create the initial objects in scene:create and store references to them, then in scene:show run a function that checks whether it should change the images.
Ok I see. So if there is a change you create the object again in scene:show ? Is that for performance or something because it would seem to make the code more than twice as long per image compared with just creating them in scene:show?
Well, I would have a creation function that can be called from either create or show. If you’re in create, always call it, if in show, do your checks and if necessary destroy then re-create. That way you have no duplicate code.
So if I set the x and y position and other parameters in scene:create, when I recreate the image with display.newImageRect in scene:show (if required) would I need to re-set the x and y position again or would they at least be remembered?
Also you say to ‘check if there’s been a change’ but now that I think about it I’m not sure how to do that. Normally the change just changes the url. I have a background in web programming so normally the change in the variable is enough to change the link and hence the image.
Well how much of the scene are you replacing? If it’s a lot you might as well purge the whole thing every time you exit.
If just the background I suppose that’s ok, are you also loading the image in scene:create? If not background will be nil the first time and it will crash.
If you are, wrap the code in a loadBackground() function that you call in both :create and :show. That way you avoid duplicate code and don’t have to change it twice if that code needs to be altered.
I have a background ~= nil check for removing the objects. It’s a few buttons and a few images. It’s pretty much the whole scene but it’s only a few buttons and a couple of images.
The loadBackground() function seems like a good idea.
Create the initial objects in scene:create and store references to them, then in scene:show run a function that checks whether it should change the images.
Ok I see. So if there is a change you create the object again in scene:show ? Is that for performance or something because it would seem to make the code more than twice as long per image compared with just creating them in scene:show?
Well, I would have a creation function that can be called from either create or show. If you’re in create, always call it, if in show, do your checks and if necessary destroy then re-create. That way you have no duplicate code.
So if I set the x and y position and other parameters in scene:create, when I recreate the image with display.newImageRect in scene:show (if required) would I need to re-set the x and y position again or would they at least be remembered?
Also you say to ‘check if there’s been a change’ but now that I think about it I’m not sure how to do that. Normally the change just changes the url. I have a background in web programming so normally the change in the variable is enough to change the link and hence the image.
Well how much of the scene are you replacing? If it’s a lot you might as well purge the whole thing every time you exit.
If just the background I suppose that’s ok, are you also loading the image in scene:create? If not background will be nil the first time and it will crash.
If you are, wrap the code in a loadBackground() function that you call in both :create and :show. That way you avoid duplicate code and don’t have to change it twice if that code needs to be altered.
I have a background ~= nil check for removing the objects. It’s a few buttons and a few images. It’s pretty much the whole scene but it’s only a few buttons and a couple of images.
The loadBackground() function seems like a good idea.