display.setDefault()

Type Function
Library display.*
Return value none
Revision Current Public Release (2017.3068)
Keywords defaults, set default, color, graphics, vector objects
See also display.getDefault()
Shapes — Paths, Fills, Strokes
display.newLine()
display.newText()
object.anchorX
object.anchorY

Overview

Set default display values including default colors for display objects, anchor point defaults, texture wrapping settings, etc.

Syntax

Any of the following are valid:

display.setDefault( key, value )

display.setDefault( key, r, g, b, alpha )

display.setDefault( key, r, g, b )

display.setDefault( key, gray )

display.setDefault( key, gray, alpha )
key (required)

String. Specifies the key to set the default value for.

gray, r, g, b, alpha (optional)

Numbers. Color values between 0 and 1.

Display Object Keys

These keys specify default anchor values and anchor bounds for all display objects.

Color Keys

A color key specifies which default color value to set.

Native Keys

Texture Keys

Important
  • For texture wrapping ("textureWrapX" and "textureWrapY"), "clampToEdge" is the only valid mode for non-power-of-two textures. To use "repeat" or "mirroredRepeat", make sure the dimensions of your textures are power of two, for example 16, 32, 64, 128, 256, etc.

  • When using one of the non-default wrap modes ("repeat" or "mirroredRepeat"), you should revert the wrap mode to default ("clampToEdge") when repeating fills are no longer required. For example, after filling an object with a wrapping texture, revert the wrap mode to default before proceeding with any other fill operations.

Camera Source

Examples

Default Anchors
-- Set default anchor point for objects to bottom-left
display.setDefault( "anchorX", 0 )
display.setDefault( "anchorY", 1 )
Non-Clamped Anchors
display.setDefault( "isAnchorClamped", false )
--display.setDefault( "isAnchorClamped", true )

local rect = display.newRect( 200, 240, 100, 100 )
rect.anchorX = -1
rect.anchorY = 1.5

transition.to( rect, { rotation=135, delay=500 } )
Fill Color and Background
-- Set default fill color for vector objects to red
display.setDefault( "fillColor", 1, 0, 0 )

-- Set default screen background color to blue
display.setDefault( "background", 0, 0, 1 )
Texture Wrap
display.setDefault( "textureWrapX", "repeat" )
display.setDefault( "textureWrapY", "repeat" )

local x,y = display.contentCenterX, display.contentCenterY
local o = display.newRect( x, y, display.contentWidth, display.contentHeight )
o.fill = { type="image", filename="fish.small.red.png" }
o.fill.scaleX = 0.1
o.fill.scaleY = 0.1
Camera Source
if ( system.getInfo( "environment" ) ~= "simulator" ) then
    display.setDefault( "cameraSource", "front" )   -- Front-facing camera
    --display.setDefault( "cameraSource", "back" )  -- Back-facing camera
end