# enchant.js 小テスト1-1 ## 課題: ゲームの初期化とplayerの作成 ## タスク: enchant()を呼び出し、ゲームライブラリを初期化します。 ゲームのコアを作成します。このとき、ディスプレイ(DISP_SIZE)のサイズ(640)も指定します。 ゲーム内で使う定数や変数を定義します。(TIME, SCORE, DISP_SIZE) ゲームで使用するすべての画像をプレロードします。 ### ヒント coreを640✖︎640の大きさで作りましょう。 ゲームで使う画像を全て用意してpreloadしましょう。 (PLAYER, COIN, EMENY) 変数(var)を定義しましょう。 playerを画面に表示しましょう。 ### 開始コード: enchant(); window.onload = function() { core.fps = 30; core.onload = function() { } } function rand(n) { return Math.floor(Math.random() * (n + 1)); } <details> <summary>解答</summary> enchant(); window.onload = function() { const PLAYER = 'player.png'; const COIN = 'coin.png'; const ENEMY = 'enemy.png'; const DISP_SIZE = 640; const TIME = 30; var score = 0; var core = new Core(DISP_SIZE, DISP_SIZE); core.preload(PLAYER, COIN, ENEMY); core.fps = 30; core.onload = function() { var player = new Sprite(100, 100); player.x = DISP_SIZE / 2; player.y = DISP_SIZE - player.height * 2; player.image = core.assets[PLAYER]; core.rootScene.addChild(player); } core.start(); } function rand(n) { return Math.floor(Math.random() * (n + 1)); } </details>
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up