Avoiding redundant variable declarations?

For my first game (using Corona and in general), I made a simple infinite runner roughly following Corona’s “Getting Started Guide”.

One of its biggest problems is that of redundancy; I’m using the same background image for every menu/screen in the game, using code like this:

scene:create() ... background = display.newImageRect( ... ) end

And it works, but I’m having to do this for every scene, and that’s annoying (and messy). Is there a way to load the images in one place as a global and reference them from other files?

For my first game (using Corona and in general), I made a simple infinite runner roughly following Corona’s “Getting Started Guide”.
 
One of its biggest problems is that of redundancy; I’m using the same background image for every menu/screen in the game, using code like this:

scene:create() … background = display.newImageRect( … )end

And it works, but I’m having to do this for every scene, and that’s annoying (and messy). Is there a way to load the images in one place as a global and reference them from other files?

Hi, I’m a newbie too.
Read this tutorial:
https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
It was very helpful for me.

Yes there is, you need to load your images into texture objects and then use that to paint a rect or image.  Note: You are responsible for the memory management and you cannot rely on the lua garbage collector doing this automatically for you.

This looks like just what I needed, thanks guys!

For my first game (using Corona and in general), I made a simple infinite runner roughly following Corona’s “Getting Started Guide”.
 
One of its biggest problems is that of redundancy; I’m using the same background image for every menu/screen in the game, using code like this:

scene:create() … background = display.newImageRect( … )end

And it works, but I’m having to do this for every scene, and that’s annoying (and messy). Is there a way to load the images in one place as a global and reference them from other files?

Hi, I’m a newbie too.
Read this tutorial:
https://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
It was very helpful for me.

Yes there is, you need to load your images into texture objects and then use that to paint a rect or image.  Note: You are responsible for the memory management and you cannot rely on the lua garbage collector doing this automatically for you.

This looks like just what I needed, thanks guys!