Automatically center all new display objects

Hello,

is there a way to tell Corona that all new DisplayObjects should automatically be centered on the screen without the need to set it manually each time:

object.x = display.contentCenterX

object.y = display.contentCenterY

Thanks

Tyr

You can construct a fonction that’s do it automatically :

local function centerF(object) if not object then return end   object.x=display.contentCenterX   object.y=display.contentCenterY   return object end

Or change it in the root of the display fonction.

So put it on the top of your main.lua file :

for obj,funct in pairs(display) do   if obj~="getDefault"and obj~="setStatusBar" and obj~="setDefault" and   type(funct) == "function" then          local initialFunction=funct     display[obj]=function(...)       local o=initialFunction(...)       o.x,o.y=display.contentCenterX,display.contentCenterY       return o     end        end end

Every display object with a “x” or “y” key-value parameter is centered.

Centering all objects from group

local function centering(group)     for i=1, group.numChildren do         local child = group[i]         child.x, child.y = display.contentCenterX, display.contentCenterY     end end

You can construct a fonction that’s do it automatically :

local function centerF(object) if not object then return end   object.x=display.contentCenterX   object.y=display.contentCenterY   return object end

Or change it in the root of the display fonction.

So put it on the top of your main.lua file :

for obj,funct in pairs(display) do   if obj~="getDefault"and obj~="setStatusBar" and obj~="setDefault" and   type(funct) == "function" then          local initialFunction=funct     display[obj]=function(...)       local o=initialFunction(...)       o.x,o.y=display.contentCenterX,display.contentCenterY       return o     end        end end

Every display object with a “x” or “y” key-value parameter is centered.

Centering all objects from group

local function centering(group)     for i=1, group.numChildren do         local child = group[i]         child.x, child.y = display.contentCenterX, display.contentCenterY     end end