左: JavaScript / 右: Flash
どちらも、Haxe + NME から生成したもの。
application.nmml
<?xml version="1.0" encoding="utf-8"?> <project> <!-- NMML reference: https://gist.github.com/1763850 --> <!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) --> <meta title="haxe_hellowrold_nme" package="com.blawat2015.haxehellowroldnme" version="1.0.0" company="mieki256" /> <!-- output --> <app main="com.blawat2015.Main" file="haxehellowroldnme" path="bin" /> <window background="#000000" fps="60" /> <window width="320" height="480" unless="mobile" /> <window orientation="landscape" vsync="true" antialiasing="0" if="cpp" /> <!-- classpath, haxe libs --> <source path="src" /> <haxelib name="nme" /> <!-- assets --> <icon path="assets/nme.svg" /> <assets path="assets/img" rename="img" /> <!-- DLLs --> <ndll name="std" /> <ndll name="regexp" /> <ndll name="zlib" /> <ndll name="nme" haxelib="nme" /> <!-- optimize JS output --> <haxeflag name="--dead-code-elimination" if="html5" /> <haxeflag name="--js-modern" if="html5" /> </project>
Main.hx
package com.blawat2015; import nme.Assets; import nme.display.Bitmap; import nme.display.Sprite; import nme.events.Event; import nme.Lib; /** * haxe + NME のテスト。 * @author mieki256 */ class Main extends Sprite { var img_bg:Bitmap; var obj : Array; var rot:Float; var SW:Int = 320; var SH:Int = 480; var BALL_MAX = 60; // コンストラクタ public function new() { super(); #if iphone Lib.current.stage.addEventListener(Event.RESIZE, init); #else addEventListener(Event.ADDED_TO_STAGE, init); #end } // 初期化処理 private function init(e) { // 背景画像を登録 img_bg = new Bitmap(Assets.getBitmapData("img/bg.jpg")); addChild(img_bg); rot = 0.0; // 手前に表示するスプライトを発生させていく obj = new Array(); var cr = 5.0; var ang = 0.0; var spd = 1.0; var scale = 0.6; var i = 0; while (i < BALL_MAX) { var spr = new Ball(ang, cr, spd, scale); addChild(spr); obj[i] = spr; ang += 0.01; cr += 3; spd += 0.08; scale += (0.4 / BALL_MAX); i++; } // 毎フレーム実行する関数を指定 addEventListener(Event.ENTER_FRAME, this_onEnterFrame); } // 毎フレーム実行される処理 private function this_onEnterFrame(event:Event):Void { // ボールを移動 for (i in 0...obj.length) { var spr:Ball = obj[i]; spr.update(); } // 背景を拡大縮小 var v = Math.sin(rot * Math.PI / 180); img_bg.scaleX = 1.2 + 0.2 * v; img_bg.x = -((SW * img_bg.scaleX) - SW) / 2; img_bg.scaleY = 1.1 - 0.1 * v; img_bg.y = -((SH * img_bg.scaleY) - SH) / 2; rot += 1; } static public function main() { var stage = Lib.current.stage; stage.scaleMode = nme.display.StageScaleMode.NO_SCALE; stage.align = nme.display.StageAlign.TOP_LEFT; Lib.current.addChild(new Main()); } }
Ball.hx
package com.blawat2015; import nme.Assets; import nme.display.Bitmap; import nme.display.Sprite; import nme.events.Event; import nme.Lib; // 手前に表示するボール状のスプライト class Ball extends Sprite { var img:Bitmap; var rot:Float; var r:Float; var rot_spd:Float; var scale:Float; public function new(ang:Float, cr:Float, spd:Float, sz:Float) { super(); // 画像を登録 img = new Bitmap(Assets.getBitmapData("img/ball.png")); addChild(img); // 角度や半径等を初期化 img.scaleX = sz; img.scaleY = sz; rot = ang; r = cr; rot_spd = spd; this.set_xy(); } // 毎フレーム呼ばれる処理 public function update():Void { set_xy(); rot += rot_spd; } // Bitmapの座標値を指定 private function set_xy():Void { var x = r * Math.cos(degToRad(rot)) + (320 / 2) - (img.width / 2); var y = r * Math.sin(degToRad(rot)) + (480 / 2) - (img.height / 2); img.x = x; img.y = y; } public inline static function degToRad(deg:Float):Float { return Math.PI / 180 * deg; } }