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]