Basic question about using Anchor and set its position x,y

In graphic 1.0, I have code like this

currPageGroup:setReferencePoint(display.CenterReferencePoint) currPageGroup.x = screenW \*0.5

The idea above is simple. There is a group of display objects, using center reference point, and the group is placed in the middle of the screen.

Now I want to migrate to G2, but I think I don’t totally understand something. I modified the above code to this and I expected the same but it’s not: 

currPageGroup.anchorX = 0.5 currPageGroup.anchorY = 0.5 currPageGroup.x = screenW \*0.5

I am very much confused about this.

You have done it good, but the reason it’s not working is because now displayGroup has setting of reference points disabled at default. There is property (check documentation for name) you must set to true. Then you set anchor points and they now will take effect.

@piotrz55

thanks, you are right, I have to add anchorChildren to true.

I have something else messed up the screen (newText() now is centered by default instead of left-top) that I have to take care of.

I used to have a line like this

    display.newText(str, x, y, …)

now I have to do

local obj = display.newText(str, x, y, ...) obj.anchorX = 0 obj.anchorY = 0 obj.x = x obj.y = y

Is there a better way? (but I don’t want to set the default like this: display.setDefault( “anchorX”, 0 ))

I have a button with no group that I use, I cannot seem to understand why the upper left corner is the anchor in the middle of the display in G2. Can anyone explain?

widget.newButton{
left = 0,
top = 0,
sheet = _Sheet,
defaultFrame =_Nfo:getFrameIndex(“dimmer-ui”),
overFrame = _Nfo:getFrameIndex(“dimmer-ui”),
isEnabled = false
}

Edit: It’s due to the parent group having an anchorX,anchorY = 0.5,0.5

Now everything is referenced by center - even when it is construction function: newText, newRect…

How do you set the anchorX and anchorY of button? Internally, they have their own group.

Please read:  http://www.coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/

And look at the discussion on anchorChildren and see if setting that option helps do what you want.

Rob

My first stop when I’m trying to figure something out is the API documentation. Second is the forum. Third or more is the blog.

I can’t find .anchorChildren anywhere in the docs. If you guys are going to write a blog post (which is nice) I think that should come after writing the updated version of the API documentation.

(Yeah, I know I sound frustrated. Guess why?)

 Jay

PS - Finally found mention of it in one of the “guides” but that’s not the API docs. :frowning:

G2.0 articles:

(1) http://www.coronalabs.com/resources/tutorials/images-audio-video-animation/

(2) http://www.coronalabs.com/blog/2013/11/06/graphics-2-0-tutorial-roundup/

You have done it good, but the reason it’s not working is because now displayGroup has setting of reference points disabled at default. There is property (check documentation for name) you must set to true. Then you set anchor points and they now will take effect.

@piotrz55

thanks, you are right, I have to add anchorChildren to true.

I have something else messed up the screen (newText() now is centered by default instead of left-top) that I have to take care of.

I used to have a line like this

    display.newText(str, x, y, …)

now I have to do

local obj = display.newText(str, x, y, ...) obj.anchorX = 0 obj.anchorY = 0 obj.x = x obj.y = y

Is there a better way? (but I don’t want to set the default like this: display.setDefault( “anchorX”, 0 ))

I have a button with no group that I use, I cannot seem to understand why the upper left corner is the anchor in the middle of the display in G2. Can anyone explain?

widget.newButton{
left = 0,
top = 0,
sheet = _Sheet,
defaultFrame =_Nfo:getFrameIndex(“dimmer-ui”),
overFrame = _Nfo:getFrameIndex(“dimmer-ui”),
isEnabled = false
}

Edit: It’s due to the parent group having an anchorX,anchorY = 0.5,0.5

Now everything is referenced by center - even when it is construction function: newText, newRect…

How do you set the anchorX and anchorY of button? Internally, they have their own group.

Please read:  http://www.coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/

And look at the discussion on anchorChildren and see if setting that option helps do what you want.

Rob

My first stop when I’m trying to figure something out is the API documentation. Second is the forum. Third or more is the blog.

I can’t find .anchorChildren anywhere in the docs. If you guys are going to write a blog post (which is nice) I think that should come after writing the updated version of the API documentation.

(Yeah, I know I sound frustrated. Guess why?)

 Jay

PS - Finally found mention of it in one of the “guides” but that’s not the API docs. :frowning:

G2.0 articles:

(1) http://www.coronalabs.com/resources/tutorials/images-audio-video-animation/

(2) http://www.coronalabs.com/blog/2013/11/06/graphics-2-0-tutorial-roundup/