A better way of setting a background fill color?

Hi everyone,

Usually, when I want a solid fill background I would create a rectangle to cover the screen and set it’s color. Just wondering if there is a better way of doing it:

Say I want scene 1 to have a black background and scene 2 to have a white background. Instead of using display.newRect couldn’t I just put:

Scene 1:

display.setDefault (“background”, 0, 0, 0)

Scene 2:

display.setDefault (“background”, 1, 1, 1)

Just seems to me like a quicker, more elegant way of changing a background color, and a way of avoiding any potential screen scaling issues - are there any problems with doing it this way though?

Thanks! :slight_smile:

Using display.setDefault() is a valid way to do what you want. But so is:

local background = display.newRect(display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight)

Of course with setDefault() you don’t have a display object. There are pros and cons to this. Some people when creating a scene in particular overlays will want to put a touch/tap handler on the background. On the other side, it’s a display object and you have to manage it.

Rob

Using display.setDefault() is a valid way to do what you want. But so is:

local background = display.newRect(display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight)

Of course with setDefault() you don’t have a display object. There are pros and cons to this. Some people when creating a scene in particular overlays will want to put a touch/tap handler on the background. On the other side, it’s a display object and you have to manage it.

Rob