I could really use the help of a Corona Guru.
I’m creating a game with a layout similar to Words With Friends. The goal is to have a gameboard that you can zoom in on and pan around, and tiles along the bottom of the screen that you can drag to the game board and will snap into place.
I have created a group for the gameboard which will ultimately hold all the tiles and background image for the board etc. I have the tiles in a separate group initially because the gameboard needs to be able to zoom and move around independently of the rest of the objects on screen.
I have a touch event listener for the tiles where I also pass in the group for the gameboard. The problem is that no matter what I do, the tiles get positioned relative to the center of the boardgroup. I would like to make them position relative to the top left to avoid having to do crazy math. I tried setting the display reference point to top left but it doesn’t seem to make a difference.
When I create the gameboard group I set the reference point to center to make it easy to position. I tried setting it to top left but this didn’t seem to make a difference. The tiles always get positioned to the center of the group.
I also made the gameboard group a physics object as I found doing so makes it really easy to drag and flick it around.
My code for the event listener is below:
function tileTouch(event, boardGroup) local body = event.target if event.phase == "began" then display.getCurrentStage():setFocus( body ) body.isFocus = true body.markX = body.x -- store x location of object body.markY = body.y -- store y location of object elseif body.isFocus then if event.phase == "moved" then local x = (event.x - event.xStart) + body.markX local y = (event.y - event.yStart) + body.markY body.x, body.y = x, y -- move object based on calculations above elseif event.phase == "ended" or event.phase == "cancelled" then body:scale(1/boardGroup.scaleMax, 1/boardGroup.scaleMax) zoomBoard(boardGroup, event) boardGroup:setReferencePoint(display.TopLeftReferencePoint) body.x = 0 --With everything Ive tried this always refers to the center body.y = 0 --of the board group. boardGroup:insert(body) display.getCurrentStage():setFocus( nil ) body.isFocus = false boardGroup:setReferencePoint( display.CenterReferencePoint ) end end return true end
Please let me know if you need to see more code. Thanks!!