Expected behavior of anchorChildren=true when default origin is 0,0

There is one thing I don’t quite understand, when I do the following:

-- use top-left origin display.setDefault('anchorX', 0) display.setDefault('anchorY', 0)

And then create a container (which has anchorChildren set to true by default).

If I add an display object onto this container, it will be positioned at the center of container, something like this:

local c = display.newContainer(display.contentWidth, display.contentHeight) local r = display.newRect(0, 0, 100, 100) c:insert(r)

What I don’t understand is the “centering” bit, so “anchor” 0,0 here basically mean the center of container? And since container’s bounding box is affected by its “anchor”, moving “anchor” to 0.5/0.5 will move the bounding box as well.

I do know setting anchorChildren=false and everything works, but I can’t seem to understand why 0,0 maps to center of container, wouldn’t most people just want a group with a mask?

@Staff,

Question 1: I’m not sure, but is ‘anchorChildren’ a valid flag/setting for containers?  I want to say, “No”, but I could be wrong.

@bitinn,

Anchor Points

Anchors are as follows:

  • anchorX - 0 is left, 0.5 is center, 1 is right.  
  • anchorY - 0 is top, 0.5 is center, 1 is bottom.

Also note that anchors can take values <0 and >1.

Containers and Anchors

I’ve verified this, and you should know that changing the default anchor does not affect the container’s placement. i.e. it is still placed in the same position as before and by its center.

General Placement and Containers

Regarding containers.  If you don’t change any anchoring properties and if you place on object at 0,0 within a container, that object will be in the center of the container.  

Summary

You didn’t show us this, bit I’m guessing you are changing the x,y position of the container to be other than <0,0>? It looks like you placed it in the center of the screen.

In any case, your code is saying: 

“Place rectangle ‘r’ at position 0,0 in the container, where 0,0 is the upper left corner of the rectangle and in the center of the container.”

Help?

I know you’re asking a general question here, but I wonder if this is driven by you wanting to achieve some specific effect.  If that is true, can you elaborate on the effect/outcome you are seeking?  We (I and others) might be able to help you achieve it.

@Staff,

Question 1: I’m not sure, but is ‘anchorChildren’ a valid flag/setting for containers?  I want to say, “No”, but I could be wrong.

@bitinn,

Anchor Points

Anchors are as follows:

  • anchorX - 0 is left, 0.5 is center, 1 is right.  
  • anchorY - 0 is top, 0.5 is center, 1 is bottom.

Also note that anchors can take values <0 and >1.

Containers and Anchors

I’ve verified this, and you should know that changing the default anchor does not affect the container’s placement. i.e. it is still placed in the same position as before and by its center.

General Placement and Containers

Regarding containers.  If you don’t change any anchoring properties and if you place on object at 0,0 within a container, that object will be in the center of the container.  

Summary

You didn’t show us this, bit I’m guessing you are changing the x,y position of the container to be other than <0,0>? It looks like you placed it in the center of the screen.

In any case, your code is saying: 

“Place rectangle ‘r’ at position 0,0 in the container, where 0,0 is the upper left corner of the rectangle and in the center of the container.”

Help?

I know you’re asking a general question here, but I wonder if this is driven by you wanting to achieve some specific effect.  If that is true, can you elaborate on the effect/outcome you are seeking?  We (I and others) might be able to help you achieve it.