Last active
December 16, 2015 23:50
-
-
Save cambiata/5516953 to your computer and use it in GitHub Desktop.
Haxe example comparing flash.display.Bitmap and starling.display.Image haxe -cp src -lib starling -swf F:/_dev/StarlingTest/bin/StarlingTest.swf -swf-header 800:600:30:FFFFFF -swf-version 11.4 -main Main -swf-lib starling.swf -D as3_native
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
package ; | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.display.PixelSnapping; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.events.Event; | |
import flash.Lib; | |
import starling.display.Image; | |
import starling.display.Sprite; | |
import starling.display.Button; | |
import starling.text.TextField; | |
/** | |
* ... | |
* @author Jonas Nyström | |
*/ | |
@:bitmap("bin/test.png") class TestBitmap extends flash.display.BitmapData { } | |
class Main extends Sprite | |
{ | |
static function main() | |
{ | |
var stage = Lib.current.stage; | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
// entry point | |
try { | |
var s = new starling.core.Starling(Main, flash.Lib.current.stage); | |
s.start(); | |
} | |
catch(e:Dynamic){ | |
trace(e); | |
} | |
} | |
public function new() { | |
super(); | |
var testBitmap = new TestBitmap(1412, 2000); | |
//----------------------------------- | |
// Using flash standard API: | |
//var img = new flash.display.Bitmap(testBitmap, PixelSnapping.AUTO, true); | |
//Lib.current.addChild(img); | |
//----------------------------------- | |
// Using starling | |
var img = starling.display.Image.fromBitmap(new Bitmap(testBitmap, PixelSnapping.AUTO, true)); | |
addChild(img); | |
//----------------------------------- | |
// Benchmarking | |
showExecTime("scroll timer", function(){ | |
for (i in 0...1000) { | |
for (v in -1000...1000) { | |
img.x = v; | |
} | |
img.x = 0; | |
for (v in -1000...1000) { | |
img.y = v; | |
} | |
img.y = 0; | |
} | |
}); | |
showExecTime("zoom timer", function() { | |
var w = 1412.0; | |
var h = 2000.0; | |
for (i in 0...3000) { | |
for (z in 1...100) { | |
img.width = w * (z / 100); | |
img.height = h * (z / 100); | |
} | |
} | |
img.width = w * (30 / 100); | |
img.height = h * (30 / 100); | |
}); | |
} | |
static function measureExecTime(func): Float{ | |
var start_time : Date = Date.now(); | |
func(); | |
var end_time : Date = Date.now(); | |
return (end_time.getTime() - start_time.getTime()); | |
} | |
static function showExecTime(explain:String, func): Void { | |
var time = measureExecTime(func); | |
trace(explain + " : " + time + "ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment