HTML 게임 예제
HTML과 JavaScript만 사용하여 게임을 개발하는 방법을 배우세요.
버튼을 눌러 빨간 정육면체를 이동하십시오:
직접 테스트 예제
이 온라인 편집기를 사용하여 코드를 편집하고, 버튼을 클릭하여 결과를 확인할 수 있습니다.
实例
function startGame() { myGamePiece = new component(30, 30, "red", 10, 120); myGamePiece.gravity = 0.05; myScore = new component("30px", "Consolas", "black", 280, 40, "text"); myGameArea.start(); } var myGameArea = { canvas : document.createElement("canvas"), start : function() { this.canvas.width = 480; this.canvas.height = 270; this.context = this.canvas.getContext("2d"); document.body.insertBefore(this.canvas, document.body.childNodes[0]); this.frameNo = 0; }, clear : function() { this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); } }