Turning from Preloader->Main->1stWorld like 2 frames of grey screen[solved]


(billy2000) #1

Hyas. After my game finishes loading i switch to main and then to my 1st world.At preloader everything is black ,on 1st world ,when it begins everything is black.But when the game switches between preloader and world i get like 1-3 frames of grey screen.I’m using flash develop and i tried to change background color to #000000(or any other color) but i still get same thing.Also tried FP.screen.color = 0x000000; but still nothing.Is there any way to solve this?


(Nicole Brauer) #2

You should post your code for the preloader/main/your-world classes so we can check if something is wrong there (maybe in the way you load your world class).


(billy2000) #3

Ok so here is the preloader:

package  
{


public dynamic class Preloader extends MovieClip
{
	private var ready:Boolean = false;
	private var clipCounter:int = 0;
	
	//transit
	[Embed(source = "../Assets/logoAndTransition/BlkTrans.png")]private const TRANSBLK:Class;
	private var transBlk:Bitmap = new TRANSBLK();
	
	//button and cursor
	[Embed(source = "../Assets/preloader/crsOpen.png")]private const CRSOPEN:Class;
	[Embed(source = "../Assets/preloader/crsPoint.png")]private const CRSFINGER:Class;
	[Embed(source = "../Assets/preloader/btnOverPlay.png")]private const BTNOVERP:Class;
	[Embed(source = "../Assets/preloader/btnPlay.png")]private const BTNNORMP:Class;
	[Embed(source = "../Assets/preloader/btnPressPlay.png")]private const BTNPRESS:Class;
	private var btnplayNorm:Bitmap = new BTNNORMP();
	private var btnplayOver:Bitmap = new BTNOVERP();
	private var btnplayPress:Bitmap=new BTNPRESS();
	private var btnPlay:Sprite = new Sprite();
	private var down_:Boolean = false;
	private var colPlay:Boolean = false;
	private var canPlay:Boolean = false;
	private var cursorFinger:Bitmap = new CRSFINGER();
	private var cursorOpen:Bitmap = new CRSOPEN();
	private var cursor:Sprite = new Sprite();
	private var stateBtnPlay:String = "not";
	
	//swfs
	[Embed(source = "../Assets/preloader/Piece.swf")]private const PIECESWF:Class;
	private var pieceSwf:MovieClip;
	private var beginFinishAnims:Boolean = false;
	private var pieceSPD:Number = 0;
	
	//background
	private const backgroundColor:uint = 0x000000;
	
	//loadding bar stuff
	[Embed(source = "../Assets/preloader/layer1.png")]private const EFILL:Class;
	[Embed(source = "../Assets/preloader/layer2.png")]private const FFILL:Class;
	[Embed(source = "../Assets/preloader/layer3.png")]private const BAR:Class;
	private var eFill:Bitmap = new EFILL();
	private var fFill:Bitmap = new Bitmap;
	private var bar:Bitmap = new BAR();
	private var ratio:Number = 0;
	
	private var eCont:Sprite = new Sprite();
	private var fCont:Sprite = new Sprite();
	private var bSprite:Sprite = new Sprite();
	
	//for loading bar to work
	// Source and buffer information.
	private var _source:BitmapData;
	private var _sourceRect:Rectangle;
	private var _buffer:BitmapData;
	private var _bufferRect:Rectangle;
	private var _bitmap:Bitmap = new Bitmap;//fFill
	
	
	
	public function Preloader() 
	{
		stage.addEventListener(Event.ENTER_FRAME, progress);
		stage.addEventListener(Event.ENTER_FRAME, cursorBehavior);
		stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
		
		
		//adding cursor
		cursor.addChild(cursorFinger);
		cursor.addChild(cursorOpen);
		stage.addChild(cursor);
		cursor.scaleX = cursor.scaleY = 2;
		cursor.x = mouseX;
		cursor.y = mouseY;
		Mouse.hide();
		
		//adding swfs
		pieceSwf = new PIECESWF();
		stage.addChild(pieceSwf);
		pieceSwf.scaleX = pieceSwf.scaleY = 2;
		pieceSwf.x = 570;
		pieceSwf.y = 443;
		
		//add loadding bar
		stage.addChild(eFill);
		stage.addChild(fFill);
		stage.addChild(bar);
		
		eFill.scaleX = eFill.scaleY = fFill.scaleX = fFill.scaleY = bar.scaleX = bar.scaleY = 2;
		eFill.x = fFill.x = bar.x = 130;
		eFill.y = fFill.y = bar.y = 400;
		theFill(FFILL);
		
		// render background
		graphics.beginFill(backgroundColor, 1);
		graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
		graphics.endFill();
		
	}
	
	//progress bar stuff next 3 functions
	private function theFill(source:*) :void
	{
		//give valors
		//var source:Bitmap = fFilll();
		
		
		var clipRect:Rectangle = new Rectangle();
		clipRect.height = fFill.height;
		
		_source = FP.getBitmap(source);
		_sourceRect = _source.rect;
		
		
		if (clipRect)
		{
			if (!clipRect.width) clipRect.width = _sourceRect.width;
			if (!clipRect.height) clipRect.height = _sourceRect.height;
			_sourceRect = clipRect;
		}
		createBuffer();
		updateBuffer();
	}
	private function createBuffer():void
	{
		
		_buffer = new BitmapData(_sourceRect.width, _sourceRect.height, true, 0);
		_bufferRect = _buffer.rect;
		
		//added by me 3 line
		_sourceRect.width = 0;
		_buffer.fillRect(_bufferRect, 0);
		_buffer.copyPixels(_source, _sourceRect, FP.zero, null, null);
		
		fFill.bitmapData = _buffer;
	}
	private function updateBuffer(clearBefore:Boolean = false):void
	{
		
		if (clearBefore) _buffer.fillRect(_bufferRect, 0);
		_buffer.copyPixels(_source, _sourceRect, FP.zero, null, null);
	}
	//cursor
	private function cursorBehavior(e:Event):void
	{
		
		//cursor on top
		if(stage.getChildIndex(cursor)<stage.numChildren-1)
		stage.setChildIndex(cursor, stage.numChildren - 1);
		//cursor movement
		cursor.x = mouseX-5;
		cursor.y = mouseY;
	}
	//play button animation and cursor when touch btn
	private function onMouseDown(e:MouseEvent):void {
		if(colPlay)
		down_ = true; 
		
		stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
	}

	private function onMouseUp(e:MouseEvent):void {
		down_ = false;  
		stage.removeEventListener(MouseEvent.MOUSE_UP,onMouseUp);
	}
	
	public function colPlayFunction(e:Event):void
	{
		if (mouseX > btnPlay.x-5 && mouseX < btnPlay.x + btnPlay.width && mouseY > btnPlay.y && mouseY < btnPlay.y + btnPlay.height) {
			colPlay = true;
			
			if (down_) {
				canPlay = true;
				
				//change images
				btnPlay.setChildIndex(btnplayPress, 2);
				btnplayOver.alpha = 0;
				btnplayNorm.alpha = 0;
				btnplayPress.alpha = 1;
				//cursor image
				cursorOpen.alpha = 0;
				cursorFinger.alpha = 1;
		    }
			else {
				//change images
				btnPlay.setChildIndex(btnplayOver, 2);
				btnplayOver.alpha = 1;
				btnplayNorm.alpha = 0;
				btnplayPress.alpha = 0;
				//cursor image
				cursorOpen.alpha = 0;
				cursorFinger.alpha = 1;
				
				if (canPlay)
				startup();
			}
		}
		else {
			colPlay = false;
			canPlay = false;
			//change images
			btnPlay.setChildIndex(btnplayNorm, 2);
			btnplayOver.alpha = 0;
			btnplayNorm.alpha = 1;
			btnplayPress.alpha = 0;
			//cursor image
			cursorOpen.alpha = 1;
			cursorFinger.alpha = 0;
		
		}
	}
	private function progress(e:Event):void 
	{
		//loadding bar
		if (loaderInfo.bytesLoaded <= loaderInfo.bytesTotal)
		ratio = loaderInfo.bytesLoaded / loaderInfo.bytesTotal;
		
		_sourceRect.width = (ratio) * 192;
		updateBuffer(true);
		
		// done loading?
		if (loaderInfo.bytesLoaded >= loaderInfo.bytesTotal && !stage.hasEventListener(Event.FRAME_CONSTRUCTED) && !beginFinishAnims)
		{
			beginAnimsAndStuff();
			//startup();
		    //ready = true;
		}
		
	}
	private function beginAnimsAndStuff():void
	{
		beginFinishAnims = true;
		stage.addEventListener(Event.FRAME_CONSTRUCTED, playAppear);
		stage.addEventListener(Event.ENTER_FRAME, pieceFly);
	}
	private function playAppear(e:Event):void
	{
		if (fFill.y > 368) {
			fFill.y -= 2;
		}
		else {
			this.parent.removeEventListener(Event.FRAME_CONSTRUCTED, playAppear);
			//adding play button
			
			btnPlay.addChild(btnplayOver);
			btnPlay.addChild(btnplayPress);
			btnPlay.addChild(btnplayNorm);
			
			stage.addChildAt(btnPlay, stage.numChildren - 1);
			
			btnPlay.scaleX = btnPlay.scaleY = 2;
			btnPlay.x = 136;
			btnPlay.y = 440;
			btnplayOver.alpha = 0;
			btnplayNorm.alpha = 1;
			btnplayPress.alpha = 0;
			
			btnPlay.addEventListener(Event.ENTER_FRAME, colPlayFunction);
			btnPlay.mouseChildren = false;
			
			fFill.alpha = 0;
		}
	}
	private function pieceFly(e:Event):void
	{
		if (pieceSwf.y > -20) {
			pieceSwf.y -= pieceSPD;
			pieceSPD += 0.8;
		}
		else {
			pieceSwf.stop();
			stage.removeEventListener(Event.ENTER_FRAME, pieceFly);
		}
	}
	private function startup():void 
	{
		// remove event listener(s)
		pieceSwf.stop();
		stage.removeEventListener(Event.ENTER_FRAME, progress);
		stage.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		btnPlay.removeEventListener(Event.ENTER_FRAME, colPlayFunction);
		
		//adding transition 
		stage.addEventListener(Event.ENTER_FRAME, transition);
		stage.addChild(transBlk);
		transBlk.x = transBlk.y = 0;
		transBlk.scaleX = transBlk.scaleY = 4;
		transBlk.alpha = 0;
		
		
	}
	private function transition(e:Event):void
	{
		transBlk.alpha += 0.1;
		if (transBlk.alpha >= 1) {
			
			//remove rest event listeners
			stage.removeEventListener(Event.ENTER_FRAME, cursorBehavior);
			stage.removeEventListener(Event.ENTER_FRAME, transition);
			stage.removeEventListener(Event.ENTER_FRAME, pieceFly);
			
			// remove all the children
			var i:int = numChildren;
			while (i --)
			{
				removeChildAt(i)
			}
			
			
			//remove the firkin swf allready!
			stage.removeChild(pieceSwf);
			
			// go to the main class
			var mainClass:Class = getDefinitionByName("Main") as Class;
			parent.addChild(new mainClass as DisplayObject);
			
			// remove self
			parent.removeChild(this)
		}
		
		
	}
}

}

side note- the transition() function switch to main

here is main:

package 
{

public class Main extends Engine 
{
	
	public function Main():void 
	{
		
		super(320, 256, 60, true);//640 x 512
		FP.screen.scale = 2;
		FP.screen.color = 0x000000;
		name = "Main";
		
	}
	
	override public function init():void 
	{
		
		super.init();
		FP.stage.scaleMode = StageScaleMode.SHOW_ALL;
        //FP.screen.x = -135;
		stage.align = "";
		FP.console.update();
		//FP.world = new Level(E.LEVEL1);
		FP.world = new SwfPlayer();
	}
	
	override public function update():void
	{
		super.update();
		
		consoleEnable();
	}
	public function consoleEnable():void
	{
		if (Input.check(Key.I))
		{
			FP.console.enable();
		}
		
		FP.console.toggleKey = Key.O;
	}
	
}

}

And here is the next world:

package  
{

public class SwfPlayer extends World 
{
	[Embed(source = "../Assets/logoAndTransition/NewSplash.swf")]private const NLOGO:Class;
	private var swf:MovieClip;
	private var logoNr:int = 0;
	private var logoTimer:int = 0;
	private var transState:String = "enter";//"enter"
	
	//transition
	private var trans_:Backdrop=new Backdrop(E.TITLEBKGR,false,false);
	private var eTrans:Entity = new Entity;
	//black
	private var backdrop_:Backdrop=new Backdrop(E.TITLEBKGR2,false,false);
	private var eBackdrop:Entity = new Entity;

	
	public function SwfPlayer() 
	{
		
		
		//backdrop
		eBackdrop.addGraphic(backdrop_);
		add(eBackdrop);
		eBackdrop.layer = 4;
		//trans add
	    eTrans.addGraphic(trans_);
		add(eTrans);
		eTrans.layer = 0;
		
		
	}
	override public function update():void
	{
	    super.update();
		
		behave();
		
	}
	private function behave():void
	{
		if (transState == "stay") return;
		
		switch(transState) {
			case "enter":
				if (trans_.alpha > 0) {
					trans_.alpha -= 0.1;
				}
				else {
					transState = "beginSwfs";
					trans_.alpha = 0;
					
				}
			break;
			
		case "beginSwfs":
			
			
		    	FP.stage.frameRate = 30;
				logoTimer = 120;
				add(new SwfTransformer( 0, 0, logoTimer, NLOGO));
				transState = "play1Swf";
			break;
			
		    case "play1Swf":
			    
				if (logoTimer > 0) logoTimer--;
				else {
					FP.stage.frameRate = 60;
				    transState = "be4leave";
				}
				
			break;
			
			case "be4leave":
			    
				transState = "leave";
				
			break;
			
			case "leave":
				if (trans_.alpha < 1) {
					trans_.alpha += 0.05;
				}
				else {
					transState = "finish";
					trans_.alpha = 1;
					FP.world = new TitleScreen();
				}
			break;
		}
		
	}
}

}

(billy2000) #4

Basically i just want to make that grey screen(that appears for 1-2 frames when i switch form preloader) black, but i don’t know how.


(billy2000) #5

I changed everything was possible from main and tried to go to many other worlds but still the same thing.That takes me to the conclusion the only problem that could be here is preloader class.But also tried many things in preloader and couldn’t make it not do that grey screen. Also that grey screen look like the one when you get a error popup.But tried to run the game in debugger and release and still same problem.


(billy2000) #6

i tried to do this at preloader in transition function:

var mainClass:Class = getDefinitionByName("Main") as Class;
parent.addChildAt(new mainClass as DisplayObject, 6);
parent.removeChild(this)

In other words i tried to make main class to be over anything when it is set as child. What happened it was really interesting. As i used a cursor image in preloader, the cursor image stopped moving(not disappearing thought) and under it, the grey background appears again for 2-3 frames and then it gets to black screen(the background of 1st world).And the cursor image remains there (over anything) for the rest of the game. I hope those details help >.<.

-edit-[idk if it helps thought] If i make this(i forgot by mistake 1 line of code and used the other also):

var mainClass:Class = getDefinitionByName("Main") as Class;
parent.addChild(new mainClass as DisplayObject);
parent.addChildAt(new mainClass as DisplayObject, 7);
parent.removeChild(this)

The grey background remains over anything and does not disappear anymore after 1-3 frames.


(billy2000) #7

so i tried some more stuff(basically anything that could get in my mind) and i did this code:

var mainClass:Class = getDefinitionByName("Main") as Class;
parent.addChild(new mainClass as DisplayObject);
parent.removeChildAt(1);
parent.removeChildAt(1);
parent.removeChildAt(1);
parent.removeChildAt(1);
parent.removeChildAt(1);
parent.removeChildAt(1);
parent.removeChildAt(1);
//parent.removeChildAt(1);  
parent.removeChild(this);

If i put this code like this anything plays as it should(with grey screen 2 frames in it).But if i put the last line form commentary too the grey screen disappear but the screen remain black and the only time it shows something its when i play the logo witch is a MovieClip. That again takes me to the conclusion FP makes initially a grey screen witch is changed after to black. My question is ,if i am right(i’m not sure rly),how can i make FP use a black screen initially when i switch to my main. PS:i already use the FP.screen.color = 0x000000; in Public function Main().I have no idea how to do this >.<.THX :smile:


(azrafe7) #8

After you set FP.screen.color add FP.screen.refresh().

The reason is that the screen buffer will be effectively filled with the specified color only in the next render step (take a look at Engine.render() to see it for yourself).


(billy2000) #9

OMG i love you!! That was the problem! Thx so much >.<


(Jacob Albano) #10

Instead of an arbitrary number of calls to removeChildAt(1), do this:

while (parent.numChildren > 0)
    parent.removeChildAt(0);

(billy2000) #11

Oh thx :smile: Sry didn’t answer .i wasn’t at computer until now XD. Well that parent.removeChieldAt was just for testing . i use this to remove my children :

var i:int = numChildren;
while (i --)
{
	removeChildAt(i)
}

Thx for help thought, u guys are the best :smile: