Help with positioning objects / container control

Hi,

Im a newbie at corona and have just started my first app.  Im having some problems with positioning object and I hope someone can advise on the best approach.

I have a square sized at 80% of the content width, position in the middle on the x and 260 down in the y.  (I read somewhere that using percentages is the best method for positioning)

I then want to add some objects to the top of my square from left to right. i.e. starting at 0,0 within the square and moving from left to right.  This is where my issue come in as I don’t know how to get the initial starting position to place my header objects.

I thought I should use a container with the same size and positioning as the square and then I could add my header objects to the container - I thought that with the correct anchors set they would start from the top left corner as I wanted.  It kind of works but it chops off my header objects around half way.

This is the code I have done.  Could somebody point me to what I have missed… I’ve been fiddling for around 3 hours with this!

I just want to know how I can achieve what I have described above. :slight_smile:

local mainGroup = display.newGroup( ) -- main part of screen sized using percentages to handle multiple screen sizes local sq1 = display.newRect(mainGroup, 0,0, display.contentWidth \* 0.8, display.contentWidth \* 0.8 ) sq1.x = display.contentWidth \* 0.5 sq1.y = 260 -- I want 5 items running along the top of sq1 i.e. some header information local itemSize = display.contentWidth \* 0.8 / 5 -- create container to sit over the top of sq1 and then add my header items to that local container = display.newContainer(mainGroup, display.contentWidth \* 0.8, display.contentWidth \* 0.8) container.x = display.contentWidth \* 0.5 container.y = 260 container.anchorX = 1 container.anchorY = 1 for x = 1, 5 do item = display.newRect((x - 1) \* itemSize,0, itemSize, 30) item:setFillColor( 0, 1/ x, 1/ x ) item.anchorX = 0 item.anchorY = 0 container:insert(item) end

Thanks in advance for your help

I’m not sure (have yet to use containers) - but might it be something about parent actor points & child anchor points must be the same.

In your code your anchor the ( C ) as 1’s but your (I)'s are 0. 

Do not take this as fact - just a suggestion to check out the docs to see if this is a possible factor.

T.

Hi ToeKnee,

Thanks for the reply… I have tried it with and without anchors and trying different values for each but still no joy.

Hi David,

I am encountering probably the same issue as you. You can refer to “Container - Shift the location of display objects” 

I’m not sure (have yet to use containers) - but might it be something about parent actor points & child anchor points must be the same.

In your code your anchor the ( C ) as 1’s but your (I)'s are 0. 

Do not take this as fact - just a suggestion to check out the docs to see if this is a possible factor.

T.

Hi ToeKnee,

Thanks for the reply… I have tried it with and without anchors and trying different values for each but still no joy.

Hi David,

I am encountering probably the same issue as you. You can refer to “Container - Shift the location of display objects”