Moving an object in isometric map by touching screen

Hi,
I am a newbie to Corona and Lime , but my company want to build a game with isometric tiled map. And then I start to learn Corona and Lime these days.

I try to follow the example “IsometricAndPlayer” which is included in Lime. I found it is useful, but i want to touch the screen to move the object. Then I added the following code :

local onTouch = function(event)  
 player.x = event.x;  
 player.y = event.y;  
end  
  
Runtime:addEventListener("touch", onTouch)  

The object has moved but not the position I touch. Anyone know why it moved to position far away from my touching point.

After I try to convert the touching point to a grid position by using worldToGridPosition() and screenToGridPosition(), like this :

local onTouch = function(event)  
 local pos = lime.utils.screenToGridPosition(map, { x = event.x, y = event.y })  
 print(dump(pos))  
  
local pos1 = lime.utils.worldToGridPosition(map, event)  
 print(dump(pos1))  
end  

Both pos and pos1 return [table]{}.

I hope somebody can help me to solve the problem. Thanks. [import]uid: 92989 topic_id: 16696 reply_id: 316696[/import]

You will probably need to convert it to an iso position first:

http://justaddli.me/api.php?c=utils&m=worldToIsometricPosition [import]uid: 5833 topic_id: 16696 reply_id: 62489[/import]

Thanks GrahamRanson.

  1. By using worldToIsometricPosition, I get a x,y value, but the object is still move the position far away from my touching point. Anybody know why this happen ?

  2. Is it possible to get a grid value from world position? [import]uid: 92989 topic_id: 16696 reply_id: 62583[/import]

Finally, I use the code below to let the object to move to the point I touch

local onTap = function(event)  
  
 local mapX, mapY = map:getPosition()  
 local diffX = event.x - mapX;  
 local diffY = event.y - mapY;  
  
 local move = checkPointAtLine({x =diffX ,y = diffY})  
  
 player.transition = transition.to( player, { time = 500, x =diffX ,y = diffY, onComplete = onTransitionComplete } )  
  
end  

Hope this can help people who needed it. [import]uid: 92989 topic_id: 16696 reply_id: 62837[/import]

However, is it possible convert the point to grid coordinate ? [import]uid: 92989 topic_id: 16696 reply_id: 62860[/import]

Currently it isn’t as I haven’t put the math in for that, if you look in lime-utils.lua you should find a function called “worldToGridPosition” which has an empty block waiting for that code. [import]uid: 5833 topic_id: 16696 reply_id: 62998[/import]