-
-
Save YellowAfterlife/dea6ad6f65162e865899 to your computer and use it in GitHub Desktop.
Comparison file, from http://yal.cc/introducing-openfl-bitfive
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.Lib; | |
import flash.display.BitmapData; | |
import flash.display.Bitmap; | |
import flash.geom.Point; | |
import flash.geom.Matrix; | |
class Main { | |
var flowSurface:BitmapData; | |
var flowBitmap:Bitmap; | |
var flowPoint:Point; | |
var flowMatrix:Matrix; | |
public function new() { | |
var flowSource:BitmapData = openfl.Assets.getBitmapData("img/water.png"); // 256x256 PNG | |
flowSurface = new BitmapData(768, 768, true, 0); | |
flowPoint = new Point(); | |
for (i in 0 ... 9) { | |
flowPoint.x = (i % 3) * 256; | |
flowPoint.y = Std.int(i / 3) * 256; | |
flowSurface.copyPixels(flowSource, flowSource.rect, flowPoint); | |
} | |
flowBitmap = new Bitmap(new BitmapData(480, 320, true, 0)); | |
Lib.current.addChild(flowBitmap); | |
flowBitmap.stage.frameRate = 60; | |
flowMatrix = new Matrix(); | |
flowBitmap.addEventListener(flash.events.Event.ENTER_FRAME, onEnterFrame); | |
onEnterFrame(null); | |
} | |
function onEnterFrame(e:Dynamic):Void { | |
var t:Float = Lib.getTimer() / 1000; | |
#if copyPixels | |
flowPoint.x = -((t * 100) % 256); | |
flowPoint.y = -((t * 70) % 256); | |
flowBitmap.bitmapData.copyPixels(flowSurface, flowSurface.rect, flowPoint); | |
#else | |
flowMatrix.tx = -((t * 100) % 256); | |
flowMatrix.ty = -((t * 70) % 256); | |
flowBitmap.bitmapData.draw(flowSurface, flowMatrix); | |
#end | |
} | |
@:keep public static function main() { | |
new Main(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment