Loading screens.

Community Forums/Monkey Talk/Loading screens.

CGV(Posted 2012) [#1]
I've noticed that every Monkey written Flash game I've seen lacks a loading screen or loading bar and just displays a white background while the game loads.

Is it not possible to give a Monkey written Flash game a loading screen or has everyone just been too lazy to bother?

Last edited 2012


therevills(Posted 2012) [#2]
It can be done, I've seen it (but cant remember who/what) - all it needs is a wrapper to do it.


CGV(Posted 2012) [#3]
I've been going through the monkey forums and I've found that Xaron came up with a simple solution.

He loads the loading screen image in OnCreate and all the rest of the game media in OnUpdate.

He claims it works on every platform. I presume he uses a state machine to prevent endless repeat loading.

This approach doesn't allow for an animated loading bar but at least you're not looking at a blank screen.

I'm still not sold on Monkey though. I'm going to stick with Flixel for my next game at least.


Matty(Posted 2012) [#4]
Actually a number of people have done this for flash - mostly using a thing called mochimedia...

http://www.monkeycoder.co.nz/Community/posts.php?topic=735

http://www.monkeycoder.co.nz/Community/posts.php?topic=1110


CGV(Posted 2012) [#5]
I use mochi in my flixel written flash games but the problem is that when you sell a site lock of your game the site may not want mochi included.

I sold a site lock to BFG and I had to strip out mochi and even playtomic.

Xaron's solution is the easy answer to this problem.


therevills(Posted 2012) [#6]
Monkey originally packed all the images in the flash file, which means the whole file had to loaded into browser before anything can be seen on the screen.

I believe now that resources can be accessed outside the flash file, so you can now do a loading screen within Monkey itself.


CGV(Posted 2012) [#7]
Single file flash games tend to go viral much more easily than multi file ones.

In fact this multi file business is one of the problems the flash developer community sees in HTML5 replacing flash.

Do you see a potential problem with Xaron's approach?


therevills(Posted 2012) [#8]
I'm not sure how Flash is loaded in the browser if it is a single file, I thought if it was a single file the whole Flash file needs to be downloaded and that what causes the wait.

When I code Pirate Solitaire using Monkey in Flash, I displayed a splash screen then load the resources, but I still get the white wait screen of death while the Flash file is downloaded to the browser.


CGV(Posted 2012) [#9]
swf files have a preloader section, like a small self contained chunk of code at the start of the file (frame 1), that can execute the moment it's loaded without having to wait for the rest of the file to download.

It doesn't make any difference if the file is a single file or multiple files it still works the same.

Typically you would just put your loading screen image and a small bit of code to update the loading bar in your preloader but I'm guessing that monkey puts everything in OnCreate into the preloader forcing you to wait for everything to load.


therevills(Posted 2012) [#10]
Ah that makes sense...

I've just looked up Flash Preloader, and it seems all the tutorials do it via the GUI - do you know how to do it in code?

If so, it should be pretty easy to add to Mojo.

Just found this:

http://www.republicofcode.com/tutorials/flash/as3preloader/

So I think it should be pretty easy to add...

Last edited 2012


CGV(Posted 2012) [#11]
No, the tut you link to is a preloader for flash games made with the Flash authoring tool.

If you download FlashDevelop, which I recommend if you want to do any AS3 coding, you'll see in the create new project dialog one of the options is 'AS3 Project with Preloader'.

This is the preloader it creates.

package 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.utils.getDefinitionByName;
	

	public class Preloader extends MovieClip 
	{
		
		public function Preloader() 
		{
			addEventListener(Event.ENTER_FRAME, checkFrame);
			loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
			// show loader
		}
		
		private function progress(e:ProgressEvent):void 
		{
			// update loader
		}
		
		private function checkFrame(e:Event):void 
		{
			if (currentFrame == totalFrames) 
			{
				removeEventListener(Event.ENTER_FRAME, checkFrame);
				startup();
			}
		}
		
		private function startup():void 
		{
			// hide loader
			stop();
			loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
			var mainClass:Class = getDefinitionByName("Main") as Class;
			addChild(new mainClass() as DisplayObject);
		}
		
	}
	
}


That's the basic preloader framework for any flash game written in pure code.

I've been using Flixel's preloader so I'm not quite sure how to make use of this generic one.


therevills(Posted 2012) [#12]
Cool! Thanks for that...

I've managed to hack Monkey to use a preloader:

http://www.therevillsgames.com/monkey/flash/MonkeyGame.html

Instructions here:

http://www.monkeycoder.co.nz/Community/posts.php?topic=2406

Hopefully Mark will add this to Monkey (or something like it).

Last edited 2012


CGV(Posted 2012) [#13]
Good Job! As always!

Now I've run out of excuses to not buy monkey.


therevills(Posted 2012) [#14]
:)

This is one of the things I like about Monkey (and BlitzMax), you can really mess with the internals of the code...

Oh and I've refined the process a tad... it now outputs to MonkeyGame.swf so you dont have to change so many things/files.