groups, containers, and anchors

Is there any way to set a display group/container settings to anchor in top left, and display objects within it to anchor top left,so that if you set the display group at 0,0 (top left), and a rect inside the group at 0,0.  The rect would show up in the top left of the screen.  Then if you changed the x and y of the group to 50,50, it would automatically translate the rect to 50,50?

I feel like this was how Corona behaved a long time ago, and it was very intuitive to me. I could create a group and loop through placing stuff using the top left starting at (0,0), and then when I was all done move the group to where I wanted it on the screen.  But now no matter what settings I use display objects always want to be placed in relation to the center of the group.  

Let’s deal with one topic at a time.

Content Space

You can force Corona to treat <0,0> as the upper left corner of the device (regardless of device) by setting config.lua as follows:

https://docs.coronalabs.com/guide/basics/configSettings/index.html#xalign-yalign

application = { content = { width = 640, -- choose your own resolution height = 960, -- choose your own resolution scale = "letterbox", xAlign = "left", yAlign = "top" } }

Personally I find this is very hard to work with. I prefer the screen centered model.  However, if it is easier for you, go for it.

Display Object Default Anchors

You can force the default anchor for all display objects (circles, rects, text, …) to be upper-left by doing this once:

https://docs.coronalabs.com/api/library/display/setDefault.html#default-anchors

-- Set default anchor point for objects to upper-left display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 )

Display Groups

https://docs.coronalabs.com/api/library/display/newGroup.html

Groups do not have anchors, but by default <0,0> aligns to the content space <0,0> so if you change content space, you change groups.

Containers

https://docs.coronalabs.com/api/library/display/newContainer.html

I believe, but may be wrong (so experiment to find out), if you change the default anchor point for display objects you also change it for containers.

If anyone else knows for sure, please reply.

Thank you!  I think that has straightened some stuff out in my head.

you may set the anchor of a group, but it won’t use them unless .anchorChildren=true – and even then, it may not behave as you expect depending on the bounds of its contained children.  bounds must be calc’d on a group in order for a “top-left” anchor for example to have any meaning at all, whereas normally groups just behave as if they have infinite bounds.  in your example, the blue group seems to have arbitrary bounds that extend “too far” to bottom-right, beyond any actual content, and i’m not sure what that “means”, but may be a source for weird behavior if you expect groups to be sized that way.

Let’s deal with one topic at a time.

Content Space

You can force Corona to treat <0,0> as the upper left corner of the device (regardless of device) by setting config.lua as follows:

https://docs.coronalabs.com/guide/basics/configSettings/index.html#xalign-yalign

application = { content = { width = 640, -- choose your own resolution height = 960, -- choose your own resolution scale = "letterbox", xAlign = "left", yAlign = "top" } }

Personally I find this is very hard to work with. I prefer the screen centered model.  However, if it is easier for you, go for it.

Display Object Default Anchors

You can force the default anchor for all display objects (circles, rects, text, …) to be upper-left by doing this once:

https://docs.coronalabs.com/api/library/display/setDefault.html#default-anchors

-- Set default anchor point for objects to upper-left display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 )

Display Groups

https://docs.coronalabs.com/api/library/display/newGroup.html

Groups do not have anchors, but by default <0,0> aligns to the content space <0,0> so if you change content space, you change groups.

Containers

https://docs.coronalabs.com/api/library/display/newContainer.html

I believe, but may be wrong (so experiment to find out), if you change the default anchor point for display objects you also change it for containers.

If anyone else knows for sure, please reply.

Thank you!  I think that has straightened some stuff out in my head.

you may set the anchor of a group, but it won’t use them unless .anchorChildren=true – and even then, it may not behave as you expect depending on the bounds of its contained children.  bounds must be calc’d on a group in order for a “top-left” anchor for example to have any meaning at all, whereas normally groups just behave as if they have infinite bounds.  in your example, the blue group seems to have arbitrary bounds that extend “too far” to bottom-right, beyond any actual content, and i’m not sure what that “means”, but may be a source for weird behavior if you expect groups to be sized that way.