Phaser 3로 게임을 만들었습니다. 작업 디렉토리에 .js 파일로 저장했습니다. 내 .html 색인 페이지에서 시작 버튼을 클릭할 때 게임을 시작하고 싶습니다. 내가 여기서 뭘 잘못하고 있니?
내가 일어나야 할 유일한 것은 마치 내가 본문에 스크립트를 포함시킨 것처럼 버튼을 클릭할 때 게임이 실행되도록 하는 것입니다.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- Title of our Page -->
<title>Video Game</title>
<!-- Phaser 3 link here -->
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
<!-- CSS For our page -->
<style type="text/css">
html, body {
margin: 0;
width: 1000px !important;
height: 750px !important;
}
script {
width: 1000px !important;
height: 750px !important;
}
</style>
</head>
<body>
<script>
var skateGame = require('skateboarding.js');
</script>
<input type = "button" onclick = "skateGame" value = "Skateboarding" />
</body>
</html>
이 시도.
당신의 .html 중에서 파일
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- Title of our Page -->
<title>Video Game</title>
<!-- Phaser 3 link here -->
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
<!-- CSS For our page -->
<style type="text/css">
html,
body {
margin: 0;
width: 1000px !important;
height: 750px !important;
}
script {
width: 1000px !important;
height: 750px !important;
}
#startGame {
background-color: #4caf50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<input type="button" id="startGame" value="Start Game" />
<script src="skateBoarding.js"></script>
</body>
</html>
그리고 skateBoarding.js에서
var startButton = document
.querySelector("#startGame")
.addEventListener("click", () => {
this.startGame();
});
// Function that start game
startGame = () => {
console.log("Game is starting");
};
이것이 작동하는지 알려주십시오. html과 js를 별도의 파일에 보관하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다