지금까지 구현한 페이지에 배경과 장애물 타일을 적용해보도록 하겠습니다.
<template>
<div id="app">
<!-- Background container -->
<div class="background"></div>
<SpriteAnimator
:frameWidth="24"
:frameHeight="24"
:animationSpeed="100"
:spriteSheet="spriteSheetPath"
:scale="2"
:obstacles="obstacles"
/>
<div
v-for="(obstacle, index) in obstacles"
:key="index"
:style="getObstacleStyle(obstacle)"
class="obstacle"
></div>
</div>
</template>
<script>
import SpriteAnimator from '@/components/SpriteAnimator.vue'
import spriteSheetPath from '@/assets/Character/Girl-Sheet.png'
export default {
name: 'App',
components: {
SpriteAnimator
},
data() {
return {
spriteSheetPath,
obstacles: [
{ x: 100, y: 100, width: 50, height: 50 },
{ x: 200, y: 150, width: 50, height: 50 },
{ x: 150, y: 300, width: 50, height: 50 }
]
}
},
methods: {
getObstacleStyle(obstacle) {
return {
position: 'absolute',
left: `${obstacle.x}px`,
top: `${obstacle.y}px`,
width: `${obstacle.width}px`,
height: `${obstacle.height}px`
}
}
}
}
</script>
<style>
#app {
position: relative;
width: 100%;
height: 95vh;
overflow: hidden;
}
/* Background styling */
.background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('@/assets/Map/TX Tileset Grass.png');
background-repeat: repeat; /* 배경 이미지를 반복하여 채움 */
z-index: -1; /* 배경이 다른 요소들 뒤에 위치하도록 설정 */
}
.obstacle {
background-image: url('@/assets/Map/TX Plant.png'), url('@/assets/Map/TX Shadow Plant.png'); /* 장애물을 풀로 지정하고 그림자도 불러옵니다. */
background-repeat: no-repeat; /* 배경 이미지 반복을 비활성화 */
background-position: -215px -180px; /* 배경 이미지의 풀 부분만 표시 */
}
</style>
.background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('@/assets/Map/TX Tileset Grass.png');
background-repeat: repeat;
z-index: -1;
}
.obstacle {
background-image: url('@/assets/Map/TX Plant.png'), url('@/assets/Map/TX Shadow Plant.png');
background-repeat: no-repeat;
background-position: -215px -180px;
}