About
Contents
STL
Android
Eigen
enchant.js
Firefox OS
OpenGL
OpenGL ES 2.0
pukiwiki
UE4
Unity
Windows Phone
Xamarin
Materials Link
その他
PR
STL
Android
Eigen
enchant.js
Firefox OS
OpenGL
OpenGL ES 2.0
pukiwiki
UE4
Unity
Windows Phone
Xamarin
キーボードイベントを検知します。上下左右のキーを押すと押した方向に画像が移動します。
// main.js enchant(); window.onload = preloadAssets; var game; var scene; var sprite; function preloadAssets() { game = new Game(320,480); game.onload = init; game.preload("images/chara1.png"); game.start(); } function init() { game.scale = 1; game.fps = 30; scene = new Scene(); scene.backgroundColor = "#000"; game.pushScene(scene); sprite = new Sprite(32, 32); sprite.image = game.assets["images/chara1.png"]; sprite.backgroundColor = "#66F"; sprite.x = 128; sprite.y = 128; scene.addChild(sprite); main(); } function main() { game.addEventListener(Event.UP_BUTTON_DOWN, moveFrame); game.addEventListener(Event.DOWN_BUTTON_DOWN, moveFrame); game.addEventListener(Event.RIGHT_BUTTON_DOWN ,moveFrame); game.addEventListener(Event.LEFT_BUTTON_DOWN, moveFrame); } function moveFrame(e) { switch (e.type) { case Event.UP_BUTTON_DOWN: sprite.y--; break; case Event.DOWN_BUTTON_DOWN: sprite.y++; break; case Event.LEFT_BUTTON_DOWN: sprite.x--; break; case Event.RIGHT_BUTTON_DOWN: sprite.x++; break; } }