Created
March 18, 2017 01:38
-
-
Save rockos/73f5a6b71e93dfdd20c55e2989238b74 to your computer and use it in GitHub Desktop.
moving robot
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<meta name="viewport" content="width=device-width, user-scalable=no" /> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<title>Getting started | phina.js</title> | |
<!-- phina.js を読み込む --> | |
<script src='http://cdn.rawgit.com/phi-jp/phina.js/v0.2.0/build/phina.js'></script> | |
<!-- メイン処理 --> | |
<script src='smp4_main.js'></script> | |
</head> | |
<body> | |
</body> | |
</html>> |
This file contains 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
// phina.js をグローバル領域に展開 | |
phina.globalize(); | |
var img = { | |
image: {'maykid_robo': 'robo.png'} | |
}; | |
// MainScene クラスを定義 | |
phina.define('MainScene', { | |
superClass: 'DisplayScene', | |
init: function() { | |
this.superInit(); | |
// 背景色を指定 | |
this.backgroundColor = '#444'; | |
var x_grid = this.gridX; // x座標 | |
var y_grid = this.gridY; // y座標 | |
var robo = Sprite('maykid_robo').addChildTo(this); // ('usagi')内が指定したキー名に相当する | |
robo.setPosition(x_grid.center(), y_grid.center()); | |
robo.width = 300; | |
robo.height = 400; | |
// 移動する速度 | |
robo.speed = 15; | |
// 動かす処理 | |
robo.update = function() { | |
this.y += this.speed; | |
// 指定範囲からはみ出さないように | |
if(this.top <= 100) { | |
this.top = 100; | |
this.speed *= -1; | |
} else if(this.bottom >= 950) { | |
this.bottom = 950; | |
this.speed *= -1; | |
} | |
} | |
} | |
}); | |
// メイン処理 | |
phina.main(function() { | |
// アプリケーション生成 | |
var app = GameApp({ | |
startLabel: 'main', // メインシーンから開始する | |
assets: img | |
}); | |
// アプリケーション実行 | |
app.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment