Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to add sprite to specific coordinates?
Started by thefest29 Jan 31 2016 10:43 AM

2 replies to this topic

Best Answer Caleb P , 31 January 2016 - 12:51 PM

Touch events give content coordinates for touch positions, but Dusk takes local coordinates for pixelsToTiles. This is easily fixed with Corona's contentToLocal function:

local localX, localY = map.layer[1]:contentToLocal(event.x, event.y)

local tileX, tileY = map.pixelsToTiles(localX, localY)

- Caleb

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

thefest29

[GLOBAL: userInfoPane.html]
thefest29
  • Enthusiast

  • 55 posts
  • Corona SDK

Hello guys.
Unfortunately i didn't find answer in documentation.
For example i have map created via Tiledmap. Size is 15x15 tiles. Can i add sprite to the tile at coordinates 7x14 without any physics?
I've tried to get coordinates manualy via touch event(  map.pixelsToTiles(event.x, event.y) ) and then i want attach sprite to the tile with received coordinates. 
It works but if i will move the camera -  map.pixelsToTiles(event.x, event.y)  will return same coordinates even if map was moved out of camera. 
For example top left corner will always return coordinates 1,1. 
Can Dusk correct calculate at which tile was tap?   
 
Thanks in advance


[TOPIC: post.html]
#2

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

  Best Answer

Touch events give content coordinates for touch positions, but Dusk takes local coordinates for pixelsToTiles. This is easily fixed with Corona's contentToLocal function:

local localX, localY = map.layer[1]:contentToLocal(event.x, event.y)

local tileX, tileY = map.pixelsToTiles(localX, localY)

- Caleb



[TOPIC: post.html]
#3

thefest29

[GLOBAL: userInfoPane.html]
thefest29
  • Enthusiast

  • 55 posts
  • Corona SDK

Touch events give content coordinates for touch positions, but Dusk takes local coordinates for pixelsToTiles. This is easily fixed with Corona's contentToLocal function:

local localX, localY = map.layer[1]:contentToLocal(event.x, event.y)

local tileX, tileY = map.pixelsToTiles(localX, localY)

- Caleb

 

Many thanks to you :)




[topic_controls]
[/topic_controls]