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