Anchor point not setting

Just started converting a large project to Graphics 2. Anchor Points have turned out to be not a simple case of substituting setReferencePoint with anchorX and anchorY.

Using setReference:BottomCenter, the rays used to rotate around the BottomCenter. But using anchorX and anchorY, each of the rays now only rotate around their center points and not 1, 0.5 (bottomCenter).

local ray = {} local rot = 0 local i for i = 1, 16 do ray[i] = display.newImageRect( imgDir.. "sunray.png", 165, 1624 ); ray[i].anchorX, ray[i].anchorY = 1, 0.5 -- Bottom Center -- THIS DOESNT WORK. -- ray[i]:setReferencePoint(display.BottomCenterReferencePoint) -- THIS WORKS. ray[i].rotation = rot rot = ray[i].rotation + 22.5 ray[i].x = 1024 ray[i].y = 768 ray[i].alpha = 1 ray[i].myName = "ray"..i end

We tried ray[i].anchorChildren = true before or after setting the anchors but that didn’t seem to work either…

Hope this is something easy. Any help would be great.

For bottom center you should use:

ray[i].anchorX, ray[i].anchorY = 0.5, 1

Thanks ingemar! It’s 12:08am here - I’ll blame that for my over sight.

One other thing as I’m trying to get my head around these anchors… Each of these 16 rays are going into a group called gp_rays. The group is then rotated from the center of the group with a transition.to. But now even when setting gp_rays.anchorX, gp_rays.anchorY = 0.5,0.5, gp_rays doesn’t rotate from the center but from the top left… does this have to do with setting anchor children to true? But when we do that the entire gp_rays group jumps up to be centered at the top left hand side of the screen.

Thanks for your awesomely fast help.

Firstly anchorChildren should only be set for the group gp_rays, not its children ray[i].

The reason the rays jump when you set gp_rays.anchorChildren = true is because the group’s x and y are 0, 0 (top left of the screen)

To get it back to where it should be set the gp_rays.x, gp_rays.y = 1024, 768 and all should be well.

Thanks ingemar.

It is just dawning on me how much of a shocking disruption it will be to implement Graphics 2.0 into our groups heavy animated app. One of the things we do a lot is swap the reference points around in a group. This will no longer be possible because to animate a group it has to set anchorChildren to true then setting the anchors will cause the group to jump around to fit the new anchors… Not to mention having to to add all this extra code to set the positions of groups which used to be inherited from the contents. So far graphics 2.0 is not a liberation but much more added work… Has anyone else come to this realisation?

It’s always a bit frustrating when breaking changes are made to a SDK.

A bit more clarification regarding anchors and groups that I’ve learned the hard way.

When anchorChildren=true is set on a group, the children’s anchors and x, y properties have no meaning other than the relative positioning of the children within the group.

It’s the group’s anchors and x, y properties that decide where the group will be displayed in the scene.

For bottom center you should use:

ray[i].anchorX, ray[i].anchorY = 0.5, 1

Thanks ingemar! It’s 12:08am here - I’ll blame that for my over sight.

One other thing as I’m trying to get my head around these anchors… Each of these 16 rays are going into a group called gp_rays. The group is then rotated from the center of the group with a transition.to. But now even when setting gp_rays.anchorX, gp_rays.anchorY = 0.5,0.5, gp_rays doesn’t rotate from the center but from the top left… does this have to do with setting anchor children to true? But when we do that the entire gp_rays group jumps up to be centered at the top left hand side of the screen.

Thanks for your awesomely fast help.

Firstly anchorChildren should only be set for the group gp_rays, not its children ray[i].

The reason the rays jump when you set gp_rays.anchorChildren = true is because the group’s x and y are 0, 0 (top left of the screen)

To get it back to where it should be set the gp_rays.x, gp_rays.y = 1024, 768 and all should be well.

Thanks ingemar.

It is just dawning on me how much of a shocking disruption it will be to implement Graphics 2.0 into our groups heavy animated app. One of the things we do a lot is swap the reference points around in a group. This will no longer be possible because to animate a group it has to set anchorChildren to true then setting the anchors will cause the group to jump around to fit the new anchors… Not to mention having to to add all this extra code to set the positions of groups which used to be inherited from the contents. So far graphics 2.0 is not a liberation but much more added work… Has anyone else come to this realisation?

It’s always a bit frustrating when breaking changes are made to a SDK.

A bit more clarification regarding anchors and groups that I’ve learned the hard way.

When anchorChildren=true is set on a group, the children’s anchors and x, y properties have no meaning other than the relative positioning of the children within the group.

It’s the group’s anchors and x, y properties that decide where the group will be displayed in the scene.