Created
October 22, 2013 17:34
-
-
Save phi-jp/7104754 to your computer and use it in GitHub Desktop.
[tmlib.js] Keyboard クラスでサクッとプレイヤーを移動させてみよう ref: http://qiita.com/phi/items/7cc359c93c64bfe2a5f0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* tmlib.js 0.2.0 | |
*/ | |
/* | |
* contant | |
*/ | |
var SCREEN_WIDTH = 465; // スクリーン幅 | |
var SCREEN_HEIGHT = 465; // スクリーン高さ | |
var SCREEN_CENTER_X = SCREEN_WIDTH/2; // スクリーン幅の半分 | |
var SCREEN_CENTER_Y = SCREEN_HEIGHT/2; // スクリーン高さの半分 | |
/* | |
* main | |
*/ | |
tm.main(function() { | |
var app = tm.display.CanvasApp("#world"); | |
app.resize(SCREEN_WIDTH, SCREEN_HEIGHT); | |
app.fitWindow(); | |
app.replaceScene(MainScene()); | |
app.run(); | |
}); | |
/* | |
* main scene | |
*/ | |
tm.define("MainScene", { | |
superClass: "tm.app.Scene", | |
init: function() { | |
this.superInit(); | |
// プレイヤー生成 | |
this.player = tm.display.TriangleShape().addChildTo(this); | |
this.player.setPosition(SCREEN_CENTER_X, SCREEN_CENTER_Y); | |
}, | |
update: function(app) { | |
var direction = app.keyboard.getKeyDirection(); // 向きを取得 | |
direction.mul(8); | |
this.player.position.add(direction); // 移動 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment