How to use preloader

29 posts

Flag Post

I’m probably just confused, but how exactly do you load assets with the preloader? I’m using flashdevelop and the preloader that is built in doesn’t seem to actually load anything, they just give you the space to display progress.

 
Flag Post

You have to fill in the blanks. You also need to make sure you aren’t loading any assets from other classes—embed any preloader-specific assets into the preloader itself.

 
Flag Post

So to load with the preloader all I have to do is embed assets into the preloader and save them as global variables or something? Wouldn’t this increase the size of my game, which is why you would use loading in the first place?

 
Flag Post

It wouldn’t increase the size, that I know of. Just embed stuff the preloader needs in the preloader class instead of wherever else it is. For example, I have a class (Asset) that pretty much contains all images, sounds, music, etc. If I tried to have my preloader pull stuff from there, the entire thing would need to load before it could be used, thus defeating the purpose of the preloader.

Oh, and they don’t need to be global variables—something like this would be just fine:

[embed code for some loading bar image]
private static const LoadingBar:Class;
[embed code for a play button]
private static const PlayButton:Class;

…etc. Since you don’t need to access them outside the preloader, you don’t need to make them global/public/whatever.

 
Flag Post

I should probably figure out how to make a preloader, but it’s all too hard…(I’m too lazy).

Normally, your game will load everything, then it will start. This leads to a period of black screen before your game starts, while it loads.
But if you have a preloader, the game just loads the things needed for that (couple of images and a bit of code), before it starts the preloader while it loads the rest of the game. So you don’t have a black screen for 20 minutes while all your pics/music/code loads.

I think I’m reasonably close?

 
Flag Post

This is generated by this code (FD preloader template).

Read it and understand how it works. You don’t need to use the Preloader.as file to embed the assets; it simply display whatever you tell it to display while it loads the embeded stufff in the whole application.

 
Flag Post

I did a bit of reading and making a preloader doesn’t seem too bad. A bit of dodginess seems to be required in Flash, but that generally is the case.

 
Flag Post

So basically I don’t need to do anything in the preloader? Do you guys have any suggestions as to when in the game I should load using URLLoader? I’m not sure when an appropriate time to load is.

 
Flag Post

For a simple preloader, you don’t need to explicitly preload anything. Just add assets (through [Embed(…)] metadata) to display objects which are loaded from the main class (not from the preloader), and they’ll end up on the second frame (which is referenced from your main class).

 
Flag Post
Originally posted by Arloistale:

So basically I don’t need to do anything in the preloader? Do you guys have any suggestions as to when in the game I should load using URLLoader? I’m not sure when an appropriate time to load is.

You can use URLLoader any time after your main class is called, not within the preloader.

 
Flag Post

BobJavona you only add the assets if you want to display anything in the preloader right? Otherwise anything that is embedded in the main class is loaded by the preloader? I already have the preloader provided by FlashDevelop. And Elyzius I know you can use URLLoader anywhere, I meant when should I do it? Should I load before the menu is created or the game is started?

 
Flag Post

To display any graphical images or have music in your game, you need to embed it somewhere. If it is embedded somewhere that is referenced by the main class, it will be ‘preloaded’, i.e. your preloader will display progress for loading that item.

You should only embed things in classes referenced directly from the preloader if you want to use them in the preloader.

 
Flag Post

Oh okay, thanks for clearing that up. About URLLoader, all the games that I’ve played so far on Kongregate only load at specific points, like before the menu or before the game. I was wondering what the best practice for when to load is.

 
Flag Post

Generally, you probably don’t want to be loading things from the internet, in the middle of your game, unless you really have to (custom user made levels or something).

 
Flag Post

So when should I embed instead of using urlloader?

 
Flag Post

Are you suggesting that I should always embed unless size becomes a problem for my game or something?

 
Flag Post

As I haven’t used Flash Develop before, I’m not entirely sure what I’m talking about, but I think your preloader should load all of your game’s assets (if that’s possible) rather than you loading them in the middle of a game, unless your game has some strange dynamic universe or something…

So, your preloader will have a couple of things embedded (a few pics or something) but it will load everything else that is embedded in the whole game (I think, based on previous replies). Generally, I’d say you would want to load all of your game’s content during that period, rather than having pauses in the game to load more stuff as you go.

 
Flag Post

Ok the other thing is I heard that games on Kongregate are limited to one file. So how/where would I store files if I wanted to save and load using URLLoader at all?

 
Flag Post

Why on earth would you use urlloader?? Just export all classes in frame 2, and put loader in frame 1

 
Flag Post

Isn’t URLLoader supposed to be the preferred way to load data like XML? So if I wanted to save and load stuff like level data I would need to use URLLoader? If I instead embedded many levels into my game wouldn’t that make it too big?

 
Flag Post

If you’re just representing the levels with a list of certain numbers, like level 1 = [1,26,2,2,4,6,7] or something, then just include it in the code. If your levels are represented by thousands upon thousands of lines of text, either, you’re doing it wrong or you might need to look for an alternate means.

But a few lines of text won’t impact the size of your game. The size of your game is mostly images and sound. Unless you’re in dire need or you’re doing custom user created level sharing, I’m not too sure why you’d need to load levels while the game is running.

If anyone has more knowledge than me though, feel free to step in.

 
Flag Post
Originally posted by Arloistale:

Isn’t URLLoader supposed to be the preferred way to load data like XML? So if I wanted to save and load stuff like level data I would need to use URLLoader? If I instead embedded many levels into my game wouldn’t that make it too big?

This depends on what your levels are. Mine include a background (static image) and even then are pretty small. Yours might be just a set of numbers (be the set big, it’s still small compared to a single sound), if so, you are already good for embedding.

And yes, about loading XMLs. See, an XML is just a string, why should it not be contained in your file? If you use JSON, the same, you just use another means to parse it. So you go [embed] with a file, set it mime-type as ‘application/octet-stream’ and use a “new XMLStoredLevel()” as a ByteArray – it can be parsed as String should you need this afterwards.

 
Flag Post
Originally posted by Arloistale:

Are you suggesting that I should always embed unless size becomes a problem for my game or something?

Yes

 
Flag Post

Let’s say i have 2 .fla, one is my game second is preloader, so i have 2 SWF, when i test preloader.swf locally it works, but how can i make it to work when uploaded on internet?

 
Flag Post

If I have many levels, like say 60 or so, won’t it look cluttered to embed them all? Is there a way I can load multiple xmls without it looking like a huge wall of text?