/* * constant */ var SCREEN_WIDTH = 640; var SCREEN_HEIGHT = 480; var SCREEN_CENTER_X = SCREEN_WIDTH/2; var SCREEN_CENTER_Y = SCREEN_HEIGHT/2; // アセット var ASSETS = { "CAT": "neko.png" }; //画像読み込み tm.asset.AssetManager.load("TitleImage" , "title.png"); /* * メイン処理(ページ読み込み後に実行される) */ tm.main(function() { // アプリケーション作成 var app = tm.app.CanvasApp("#world"); app.resize(SCREEN_WIDTH, SCREEN_HEIGHT); // リサイズ app.fitWindow(); // 自動フィット app.replaceScene(TitleScene()); // 実行 app.run(); }); /** * TitleScene */ tm.define("TitleScene", { superClass : "tm.app.TitleScene", init : function() { this.superInit({ title : "タイトル画面", width : SCREEN_WIDTH, height : SCREEN_HEIGHT, backgroundImage : "TitleImage" }); }, update: function(app) { var key = app.keyboard; if (key.getKey("z")) { // シーンの遷移 var loadingScene = tm.app.LoadingScene({ assets: ASSETS, nextScene: MainScene, width: SCREEN_WIDTH, height: SCREEN_HEIGHT }); this.app.replaceScene(loadingScene); } } }); tm.define("MainScene", { superClass: "tm.app.Scene", init: function() { // 親の初期化 this.superInit(); this.enemy = tm.app.StarShape(64,64); this.addChild(this.enemy); // シーンに追加 this.star = tm.app.Sprite("CAT"); this.addChild(this.star); // シーンに追加 }, update: function(app) { var p = app.pointing; // マウス位置 or タッチ位置に移動 this.star.x = p.x; this.star.y = p.y; this.enemy.x = 300; this.enemy.y = 300; //当たり判定 if(this.star.isHitElement(this.enemy) && this.enemy.visible == true){ this.enemy.visible = false; } // クリック or タッチ中は回転させる if (app.pointing.getPointing() == true) { this.star.rotation += 15; } //キーボタン受付 var key = app.keyboard; if (key.getKey("z")) { this.star.scaleX += 0.1; this.star.scaleY += 0.1; } }, });