Skip to content

Instantly share code, notes, and snippets.

@steverichey
Created June 12, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverichey/95a900803a996369a2c9 to your computer and use it in GitHub Desktop.
Save steverichey/95a900803a996369a2c9 to your computer and use it in GitHub Desktop.
The preloader for Don't Move, uses HaxeFlixel 4.0.0-dev
package states;
import flash.Lib;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flixel.system.FlxBasePreloader;
class Preloader extends FlxBasePreloader
{
private var _progressBar:Bitmap;
inline static private var BAR_HEIGHT:Int = 32;
inline static private var BAR_WIDTH:Int = 632;
/**
* this class mimics the look of the levelup bar from playstate but is drawn programmatically.
* this is to prevent importing anything unnecessary, like PNG files. as a result, everything
* is hand-coded to use 4x pixels, like the rest of the game.
*/
override private function create():Void
{
#if !FLX_NO_DEBUG
minDisplayTime = 4;
#end
var border1:Bitmap = new Bitmap( new BitmapData( BAR_WIDTH - 8, 4, false, 0xff949494 ) );
var border2:Bitmap = new Bitmap( new BitmapData( 4, BAR_HEIGHT - 8, false, 0xff949494 ) );
var border3:Bitmap = new Bitmap( new BitmapData( 4, BAR_HEIGHT - 8, false, 0xff545454 ) );
var border4:Bitmap = new Bitmap( new BitmapData( BAR_WIDTH - 8, 4, false, 0xff545454 ) );
_progressBar = new Bitmap( new BitmapData( 1, BAR_HEIGHT - 8, false, 0xffE5240F ) );
var progressBarShine = new Bitmap( new BitmapData( BAR_WIDTH - 16, 4, false ) );
_progressBar.x = border4.x = border1.x = Std.int( Lib.current.stage.stageWidth / 2 ) - Std.int( border1.width / 2 );
border1.y = Std.int( Lib.current.stage.stageHeight / 2 ) - Std.int( BAR_HEIGHT / 2 );
border2.x = border1.x - 4;
_progressBar.y = border3.y = border2.y = border1.y + 4;
border3.x = border1.x + border1.width;
border4.y = border2.y + border2.height;
progressBarShine.x = border4.x + 4;
progressBarShine.y = border3.y + 4;
addChild( border1 );
addChild( border2 );
addChild( border3 );
addChild( border4 );
addChild( _progressBar );
addChild( progressBarShine );
}
/**
* Fill the bar as progress continues. note that it only updates every 4 pixels, mimicking the 4x resolution
* of the rest of the game.
*/
override private function update(Percent:Float):Void
{
_progressBar.width = Std.int( Percent * ( BAR_WIDTH - 8 ) / 4 ) * 4 + 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment