Skip to content

Instantly share code, notes, and snippets.

@aberloni
Last active August 29, 2015 14:19
Show Gist options
  • Save aberloni/61c8b276afea811a5386 to your computer and use it in GitHub Desktop.
Save aberloni/61c8b276afea811a5386 to your computer and use it in GitHub Desktop.
A haxeflixel class to transform a bitmap file on the user harddrive (absolute path) to FlxSprite
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.group.FlxGroup;
import flixel.util.FlxColor;
import flash.display.BitmapData;
/**
* ...
* @author a.berlemont
* https://github.com/HaxeFlixel/flixel-demos/blob/master/User%20Interface/FileBrowse/source/PlayState.hx
*/
class AtlasBrowser extends FlxGroup
{
public function new()
{
super();
getAsset("C:\Users\[user]\Desktop\[file].jpg");
}
function getAsset(path:String):Void {
var sp:FlxSprite = new FlxSprite();
add(sp);
var data:BitmapData = BitmapData.load(path);
var imgWidth:Float = FlxG.width / data.width;
var imgHeight:Float = FlxG.height / data.height;
sp.makeGraphic(Std.int(data.width), Std.int(data.height), FlxColor.BLACK);
sp.pixels = data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment