why does setReferencePoint() on an image in a group move the image?

On the Display Objects page, the docs state : “Changing the object’s reference point will change the object’s x and y values without moving the object.”

However I have an example of setting the reference point resulting in my image moving. This is after I’ve scaled the image, and the image is in a group, so perhaps it has to do with the interaction of all that.

I’ve got a tile image that is 60x60 pixels, to fit into a grid. but when it is initially displayed outside the grid, I make it larger. The player then drags it into the grid. When they start dragging, I create a smaller image for them to drag into the grid.

I’m trying to position this larger image on the lower left corner of the screen, with 5 pixels between it and the left and bottom of the screen. The image is actually a Display Group because I’m putting a small icon on the larger icon. Here’s what I’m doing:

[lua]newTile = display.newGroup()
mainImg = display.newImage(“myImage”, 0, 0)
iconSize = 60
cellSize = 42 – this is generated from the screen size, # of tiles I want, padding between tiles, etc.; for the sake of discussion this is what I get for 7 tiles across a screen 360 pixels wide with padding
mainImg:setReferencePoint(display.TopLeftReferencePoint)
mainImg.xScale = ( (cellSize * 2) / iconSize)
mainImg.yScale = ( (cellSize * 2) / iconSize)
– mainImg:setReferencePoint(display.CenterReferencePoint) – uncomment this, and the image shifts up and left several pixels
newTile:insert( mainImg )

– add small icon to group here

– now try to position the whole thing; default referencePoint of the group is TopLeft
newTile.x = 5
newTile.y = display.contentHeight - 5 - newTile.contentHeight[/lua]

What am I missing?
[import]uid: 82378 topic_id: 25424 reply_id: 325424[/import]

I could be wrong, but as I understood it the default referencepoint is always Center, not TopLeft…

mainImg = display.newImage("myImage.png", 0, 0) -- uses TopLeftReferencePoint mainImg.x = 20 -- uses CenterReferencePoint, I think

What I’m not clear about is whether your referencepoint moves automatically if you scale the object; I wouldn’t be surprised if it does not, and you need to set the point again.

What happens if you setReferencePoint after inserting into the group?

EDIT: I probably wasn’t very clear; the basic thing I’m suspicious of is that it could very well be the :insert() function thats changing your image position, not the :setReferencePoint(). [import]uid: 41884 topic_id: 25424 reply_id: 102787[/import]