Skip to content
Browse files

Style preloader like a C64 loading screen.

  • Loading branch information...
1 parent 1177d31 commit 83f2483b103c56e67b2e6ff28f4d078b18d43dfc @djcsdy djcsdy committed
Showing with 56 additions and 34 deletions.
  1. +56 −34 src/net/noiseinstitute/youarenowinspace/Preloader.as
View
90 src/net/noiseinstitute/youarenowinspace/Preloader.as
@@ -1,25 +1,34 @@
package net.noiseinstitute.youarenowinspace {
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
import flash.utils.getDefinitionByName;
[SWF(width="768", height="576", backgroundColor="#000000", frameRate="60")]
public class Preloader extends Sprite {
private static const MAIN_CLASS_NAME:String ="net.noiseinstitute.youarenowinspace.Main";
- private static const BACKGROUND_COLOUR:uint = 0x000000;
- private static const FOREGROUND_COLOUR:uint = 0xFFFFFF;
+ private static const PROGRESS_BAR_BACKGROUND_COLOUR:uint = 0x000000;
+ private static const PROGRESS_BAR_FOREGROUND_COLOUR:uint = 0xFFFFFF;
- [Embed(source="/net/flashpunk/graphics/04B_03__.TTF", embedAsCFF="false", fontFamily="default")]
- private static const FONT:Class;
+ private static const PROGRESS_BAR_FRAME_SIZE:int = 2;
+
+ private static const MIN_COLOUR_BAR_SIZE:int = 1152;
+ private static const MAX_COLOUR_BAR_SIZE:int = 4608;
+
+ private static const COLOUR_BAR_ZOOM:int = 2;
+
+ private static var colours:Vector.<int> = new <int>[
+ 0x000000, 0xFFFFFF, 0x68372B, 0x70A4B2, 0x6F3D86, 0x588D43, 0x352879, 0xB8C76F,
+ 0x6f4f25, 0x433900, 0x9A6759, 0x444444, 0x6C6C6C, 0x9AD284, 0x6C5EB5, 0x959595];
+
+ private var colourIndex:int = 0;
+ private var colourBarSize:int = 0;
private var progressBar:Shape;
- private var text:TextField;
private var progressBarX:int;
private var progressBarY:int;
@@ -27,15 +36,18 @@ package net.noiseinstitute.youarenowinspace {
private var progressBarWidth:int;
private var progressBarHeight:int;
- private static const PROGRESS_BAR_FRAME_SIZE:int = 2;
+ private var colourBars:BitmapData;
public function Preloader() {
const stageWidth:int = stage.stageWidth;
const stageHeight:int = stage.stageHeight;
- graphics.beginFill(BACKGROUND_COLOUR);
- graphics.drawRect(0, 0, stageWidth, stageHeight);
- graphics.endFill();
+ colourBars = new BitmapData(stageWidth / COLOUR_BAR_ZOOM, stageHeight / COLOUR_BAR_ZOOM, false, colours[0]);
+ var colourBarsBitmap:Bitmap = new Bitmap(colourBars);
+ colourBarsBitmap.scaleX = 2;
+ colourBarsBitmap.scaleY = 2;
+ colourBarsBitmap.smoothing = false;
+ addChild(colourBarsBitmap);
progressBarWidth = stageWidth * 0.8;
progressBarHeight = 20;
@@ -43,55 +55,65 @@ package net.noiseinstitute.youarenowinspace {
progressBarX = (stageWidth - progressBarWidth) * 0.5;
progressBarY = (stageHeight - progressBarHeight) * 0.5;
- graphics.beginFill(FOREGROUND_COLOUR);
- graphics.drawRect(progressBarX - PROGRESS_BAR_FRAME_SIZE,
+ var frame:Shape = new Shape();
+
+ frame.graphics.beginFill(PROGRESS_BAR_BACKGROUND_COLOUR);
+ frame.graphics.drawRect(progressBarX - PROGRESS_BAR_FRAME_SIZE*2,
+ progressBarY - PROGRESS_BAR_FRAME_SIZE*2,
+ progressBarWidth + PROGRESS_BAR_FRAME_SIZE * 4,
+ progressBarHeight + PROGRESS_BAR_FRAME_SIZE * 4);
+ frame.graphics.endFill();
+
+ frame.graphics.beginFill(PROGRESS_BAR_FOREGROUND_COLOUR);
+ frame.graphics.drawRect(progressBarX - PROGRESS_BAR_FRAME_SIZE,
progressBarY - PROGRESS_BAR_FRAME_SIZE,
progressBarWidth + PROGRESS_BAR_FRAME_SIZE * 2,
progressBarHeight + PROGRESS_BAR_FRAME_SIZE * 2);
- graphics.endFill();
+ frame.graphics.endFill();
+
+ addChild(frame);
progressBar = new Shape();
addChild(progressBar);
- text = new TextField();
- text.textColor = FOREGROUND_COLOUR;
- text.selectable = false;
- text.mouseEnabled = false;
- text.defaultTextFormat = new TextFormat("default", 16);
- text.embedFonts = true;
- text.autoSize = TextFieldAutoSize.LEFT;
- text.text = "0%";
- text.x = (stageWidth - text.width) * 0.5;
- text.y = stageHeight * 0.5 + progressBarHeight;
-
- addChild(text);
-
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
if (hasLoaded()) {
graphics.clear();
- graphics.beginFill(BACKGROUND_COLOUR);
+ graphics.beginFill(PROGRESS_BAR_BACKGROUND_COLOUR);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
graphics.endFill();
start();
} else {
+ colourBars.lock();
+ var position:int = 0;
+ const maxPosition:int = colourBars.width * colourBars.height;
+ while (position < maxPosition) {
+ while (colourBarSize > 0 && position < maxPosition) {
+ colourBars.setPixel(position % colourBars.width, position / colourBars.width, colours[colourIndex]);
+ ++position;
+ --colourBarSize;
+ }
+ if (position < maxPosition) {
+ colourIndex = (colourIndex + 1) % colours.length;
+ colourBarSize = MIN_COLOUR_BAR_SIZE + Math.random() * (MAX_COLOUR_BAR_SIZE - MIN_COLOUR_BAR_SIZE);
+ }
+ }
+ colourBars.unlock();
+
var progress:Number = (loaderInfo.bytesLoaded / loaderInfo.bytesTotal);
if (isNaN(progress)) {
progress = 0;
}
progressBar.graphics.clear();
- progressBar.graphics.beginFill(BACKGROUND_COLOUR);
+ progressBar.graphics.beginFill(PROGRESS_BAR_BACKGROUND_COLOUR);
progressBar.graphics.drawRect(progressBarX, progressBarY,
progress * progressBarWidth, progressBarHeight);
progressBar.graphics.endFill();
-
- text.text = String(Math.round(progress * 100)) + "%";
-
- text.x = (stage.stageWidth - text.width) * 0.5;
}
}

0 comments on commit 83f2483

Please sign in to comment.
Something went wrong with that request. Please try again.