Map object position as tile coordinates, map objects correctly snap to each tile now when moving, and fixed bug of placing objects over eachother on the same tile
This commit is contained in:
@ -5,15 +5,19 @@
|
||||
<script setup lang="ts">
|
||||
import type { PlacedMapObject, TextureData } from '@/application/types'
|
||||
import { loadTexture } from '@/composables/gameComposable'
|
||||
import { calculateIsometricDepth } from '@/composables/mapComposable'
|
||||
import { calculateIsometricDepth, tileToWorldXY } from '@/composables/mapComposable'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import { Image, useScene } from 'phavuer'
|
||||
import { computed, onMounted } from 'vue'
|
||||
import config from '@/application/config'
|
||||
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
|
||||
import Tilemap = Phaser.Tilemaps.Tilemap
|
||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer
|
||||
|
||||
const props = defineProps<{
|
||||
placedMapObject: PlacedMapObject
|
||||
placedMapObject: PlacedMapObject,
|
||||
tileMap: Tilemap
|
||||
tileMapLayer: TilemapLayer
|
||||
}>()
|
||||
|
||||
const gameStore = useGameStore()
|
||||
@ -32,12 +36,11 @@ const imageProps = computed(() => ({
|
||||
}))
|
||||
|
||||
function calculateObjectPlacement(mapObj: PlacedMapObject) : {x: number; y: number} {
|
||||
let position = { x: mapObj.positionX, y: mapObj.positionY }
|
||||
let halfTileWidth = config.tile_size.width/2
|
||||
let halfTileHeight = config.tile_size.height/2
|
||||
let position = tileToWorldXY(props.tileMapLayer, mapObj.positionX, mapObj.positionY)
|
||||
|
||||
return {
|
||||
x: position.x-mapObj.mapObject.frameWidth/2,
|
||||
y: position.y-mapObj.mapObject.frameHeight/2-halfTileHeight
|
||||
x: position.worldPositionX-mapObj.mapObject.frameWidth/2,
|
||||
y: position.worldPositionY-mapObj.mapObject.frameHeight/2+config.tile_size.height
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user