게임 플레이에 필요한 기본적인 동작들과 UI를 완성한 후 스테이지 변환을 위해 css 파일에 있던 background-image를 js 코드에서 초기화하도록 코드를 변경하고 있었다.
/* 기존 코드 */
.game_app .game {
position: absolute;
left: 0;
bottom: 0;
z-index: 0;
width: 70000000000px;
height: 100%;
background-image: url('../lib/backgrounds/game/dragon.png');
background-repeat: repeat-x;
background-size: auto 100%;
}
여기서 background-image 경로를 그대로 복사해
init() {
gameBackground.gameBox.style.backgroundImage = "url('../lib/backgrounds/game/dragon.png')";
}
js 파일에 넣자 이미지가 로드되지 않는 에러가 발생했다.
js 코드의 경로를
init() {
gameBackground.gameBox.style.backgroundImage = "url('./lib/backgrounds/game/dragon.png')";
}
이렇게 수정하자 정상적으로 동작한다.
잘 동작해서 다행이지만 이유를 모르겠다..
아는 사람?
728x90
'JS & CSS & HTML' 카테고리의 다른 글
Font Awesome : HTML에 아이콘 삽입 (0) | 2022.04.20 |
---|---|
JS LocalStorage (0) | 2022.04.19 |
CSS transition (0) | 2022.03.31 |
JS arrow function (0) | 2022.03.31 |
JS 배열 요소 삭제 (0) | 2022.03.31 |