I need help with positioning. I have a newRect in the center to place other objects in the middle of that rect, but when I do, the other rectangles don’t show up. The rectangle is in a displayGroup with other objects too, and I want to keep those objects together with the rectangle, so I tried moving them with the group, setting the group’s x and y to the newRect so that it is in the center, but it just vanishes unless I make the non-displayGroup rectangle inside the displayGroup in the center of the newRect. Hope this makes sense lol. Do I really need to reposition each and every individual displayObject in the displayGroup to get it to fit in the center? I thought that that’s what displayGroups were for, repositioning mutiple objects the same amount, but it doesn’t seem to be working that way.
I got lost in your description. One thing to look for is to make sure the"background" newRect isn’t in front of and covering all the other ones.
As far as the positioning goes, if you position the other objects relative to the background newRect you should be okay. For example,
newObject.x = bgNewRect.x + 20 newObject.y = bgNewRect.y + 20
…would position that newObject a little down from the upper-left of the bgNewRect.
If none of that helps, you might need to post some actual code. Or maybe someone else will be by who groks what you were trying to say.
Jay
So the position is based on the upper left corner? I’ve read that the position is based on the center unless you specifically change where the position is based on with setReferencePoint. Is it that sometimes its based on the center, sometimes based on the upper left corner by default? If so, when is it which one? Thanks.
No, defaults are all based on the center now – you can change that by changing the anchorX and anchorY properties of an object. (Don’t use setReferencePoint() anymore, it’s been ditched.)
My example put the smaller object in the upper-left corner of the background newRect, but I could have just as easily put it in the lower-right corner of the background newRect:
newObject.x = (bgNewRect.x + bgNewRect.width/2) - 20 newObject.y = (bgNewRect.y + bgNewRect.height/2) - 20
I’m just saying that if you position the other objects relative to the background newRect then you can keep them all together.
Once you have all the images inserted into the display group then you can move that display group and all of the children will move, but you don’t really move the display group around to position the individual objects you’re inserting into it.
Jay
Don’t forget if you want to move all the objects in the group with the group you need to set it’s anchorChildren property to true.
I’m not using Graphics 2.0 - Im still using the older version of Corona, so all this anchor stuff doesn’t exist for me yet lol.
I think the problem is that even though I set it to the center, for some reason the group is going offscreen even though I set it to the x and y of the object :P. Weird.
well without seeing the code with some comment about what you want it to do it will be hard to help.
Oh ok :P. I have a feeling that the problem is not that the square vanishes, but it is moved off the screen for some reason, when I’m trying to get it in the middle of the screen. I tried subtracting 30 from it and I saw it in the upper corner so yeah :P.
Note that when you are moving a display group (display.newGroup), the x-Position will be 0 wherever it is created.
For example if the display group is in the center of the screen, the “displaygroup.x is 0”. Same to y-position.
@yosu as far as I know that only holds in G2 if anchorCildren is false. In compatibility mode groups have x and y as they did in G1
I’m still a bit confused. I’ve read in the “Learn Corona SDK Game Development” book that I have that sometimes it’s positioned based on left corner and sometimes its based on center depending on how you are positioning it code wise or something like that.
@rothgerry, last fall we changed our graphics engine to make positioning more consistent. Whenever you pass an X, Y to a display.* function to create a new object, the value is the center of the object. In the old graphics engine it was sometimes the center and sometimes the top left corner. All calls should be consistent now.
There are a bunch fo resources, like the learning books that have not been updated or possibly and older version, that may still tell you how to do things the old way.
Rob
Ahh ok thanks a ton! So now it’s always the center unless you specifically call display.setReferencePoint whether you are positioning it from the function or changing the value after calling the function. Is this correct?
Well graphics 2.0 gets rid of setReferencePoint in favor of Anchor Points. They do basically the same thing.
http://coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/
http://docs.coronalabs.com/guide/graphics/transform-anchor.html
Ok thanks!
I got lost in your description. One thing to look for is to make sure the"background" newRect isn’t in front of and covering all the other ones.
As far as the positioning goes, if you position the other objects relative to the background newRect you should be okay. For example,
newObject.x = bgNewRect.x + 20 newObject.y = bgNewRect.y + 20
…would position that newObject a little down from the upper-left of the bgNewRect.
If none of that helps, you might need to post some actual code. Or maybe someone else will be by who groks what you were trying to say.
Jay
So the position is based on the upper left corner? I’ve read that the position is based on the center unless you specifically change where the position is based on with setReferencePoint. Is it that sometimes its based on the center, sometimes based on the upper left corner by default? If so, when is it which one? Thanks.
No, defaults are all based on the center now – you can change that by changing the anchorX and anchorY properties of an object. (Don’t use setReferencePoint() anymore, it’s been ditched.)
My example put the smaller object in the upper-left corner of the background newRect, but I could have just as easily put it in the lower-right corner of the background newRect:
newObject.x = (bgNewRect.x + bgNewRect.width/2) - 20 newObject.y = (bgNewRect.y + bgNewRect.height/2) - 20
I’m just saying that if you position the other objects relative to the background newRect then you can keep them all together.
Once you have all the images inserted into the display group then you can move that display group and all of the children will move, but you don’t really move the display group around to position the individual objects you’re inserting into it.
Jay
Don’t forget if you want to move all the objects in the group with the group you need to set it’s anchorChildren property to true.
I’m not using Graphics 2.0 - Im still using the older version of Corona, so all this anchor stuff doesn’t exist for me yet lol.
I think the problem is that even though I set it to the center, for some reason the group is going offscreen even though I set it to the x and y of the object :P. Weird.