Created
February 10, 2017 09:04
-
-
Save rockos/5e21b884ddab61e99349e517f7c18252 to your computer and use it in GitHub Desktop.
Move your image using phina.js
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='smp6_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 = 200; | |
robo.height = 300; | |
this.player = robo; | |
}, | |
// 動かす処理 | |
update: function(app) { | |
var keyboard = app.keyboard; | |
// 左右移動 | |
if (keyboard.getKey('left')) { | |
this.player.x -= 8; | |
this.player.scale.x = 1; | |
} | |
if (keyboard.getKey('right')) { | |
this.player.x += 8; | |
this.player.scale.x = -1; | |
} | |
// 上下移動 | |
if (keyboard.getKey('up')) { | |
this.player.y -= 8; | |
} | |
if (keyboard.getKey('down')) { | |
this.player.y += 8; | |
} | |
} | |
}); | |
// メイン処理 | |
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