tmlib.js 2.0 で tm.input.Keyboard
クラスに getKeyDirection()
method を
追加しました.
これを使えばサクッとキーボードでプレイヤーを動かすような
ゲームを作ることができます.
Example
Demo
/*
* 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); // 移動
}
});