| | |
| | | } |
| | | |
| | | const onDrop = (sprite, x, y) => { |
| | | const { mapX, mapY } = Utils.getRealPosition(x, y, mapContainer.scale.x); |
| | | const { mapX, mapY } = Utils.getRealPosition(x, y, mapContainer); |
| | | sprite.x = mapX; |
| | | sprite.y = mapY; |
| | | mapContainer.addChild(sprite); |
| | |
| | | mapContainer = param; |
| | | } |
| | | |
| | | export const getRealPosition = (x, y, scale) => { |
| | | export const getRealPosition = (x, y, mapContainer) => { |
| | | const rect = app.view.getBoundingClientRect(); |
| | | return { |
| | | mapX: (x - rect.left) / scale, |
| | | mapY: (y - rect.top) / scale |
| | | mapX: (x - rect.left) / mapContainer.scale.x - mapContainer.x / mapContainer.scale.x, |
| | | mapY: (y - rect.top) / mapContainer.scale.y - mapContainer.y / mapContainer.scale.y |
| | | } |
| | | } |