...so how do we use the web event, exactly?
#1
Posted 30 September 2011 - 09:32 PM
Many thanks, please help because I really need this feature for my game.
#2
Posted 30 September 2011 - 09:40 PM
Web events
This event is triggered exclusively in HTML5 games. Adding a sound, sprite or background with the functions sound_add, sprite_add and background_add, in HTML5, will result in a delay (depending on internet speed and image server speed) before the resource is actually added and available. This event (Sound Loaded for an added sound, Image Loaded for an added sprite or background) will trigger when the resource is actually loaded in.
I assume you would use like it is defined in the manual, as a trigger of sorts.
Say you were making a music player and wanted to load a user-defined external sound (if that's possible), you would tell it to add the sound in wherever you handle the user-loading, and then in the Sound Loaded event you would tell it to play that sound.
I may be spreading misinformation, but that's what I've gathered from that definition. I also assume it handles multiple file loadings in a queue-like manner.
#3
Posted 30 September 2011 - 11:43 PM
Say you were making a music player and wanted to load a user-defined external sound (if that's possible)
Possible.
I also assume it handles multiple file loadings in a queue-like manner.
I haven't tried them either but from what I've read in the manual I also assume multiple loading are processed in a queue, otherwise it wouldn't be that useful.
#4
Posted 01 October 2011 - 09:06 AM
Nobody seems to know.
#5
Posted 01 October 2011 - 09:10 AM
Once the download for teh ressource is done the Web Event (Image loaded, Sound Loaded) will be triggered.... yeah, this would make perfect sense to me.
#6
Posted 01 October 2011 - 09:43 AM
Now, the big issue with stuff being loaded from the web is that it can also take a long time. With windows, if you load a file, it'll pop up in well under a second, probably well under half a second! But with the web... well, that just isn't going to happen, it can take tens of seconds - or more!. So, to help deal with this when you want to load assets, we have these new events: image load and sound load.
What these do is throw an event when one of the assets you just requested is actually loaded, plain and simple. So lets see how you use them.....
First, how do you set a load going?
mysprite1 = sprite_add("2_sprite.png", 2, false,false, 0,0);
mysprite2 = sprite_add("72x72_icon.png", 1, false,false, 0,0);
mysprite3 = sprite_add("background2.png", 1, false,false, 0,0);
These are your normal "add" functions, and sound and background adding work just as well.
Next, inside the events you now use a new built in variable (which is only valid inside the event) to access the details of the loaded file - like this...
var name,spid,stat; name = ds_map_find_value(async_load, "filename" ); spid = ds_map_find_value(async_load, "id" ); stat = ds_map_find_value(async_load, "status" );
You can then use this to "enable" files that you have been waiting on.
My simple little test current enables stuff like this...
if( stat<0 ){
show_message("Error loading "+name);
}else{
if( spid == mysprite1 )sprite_loaded[0] = true;
if( spid == mysprite2 )sprite_loaded[1] = true;
if( spid == mysprite3 )sprite_loaded[2] = true;
}
At some point, we will also be adding "File Loaded" events for when you want to load text files (currently not binary), and don't want to "block".
I realise this is a little different from normal GML style of code, but we think it's the most flexible, and extensible.
And that's all there is to it. Very simple, but incredibly powerful. These functions will actually now allow you to do full, seamless streaming like never before, you can wander around massive maps, pulling in new tiles as you go, all without stalling or stuttering like you would on windows.
You could even load the next level in while playing the current one, because it should have little or no impact on the level your playing.
As I said... very powerful, but now the bad news... these are only available on GameMaker:HTML5 just now, when you do sprite_add() on windows, it'll come in at once as it did before, but if your clever, you can certainly work around this by using the os_browser constant which IS available across the board.
Hope this helps.
#7
Posted 01 October 2011 - 03:47 PM
I'm going to try this out
one question, though - do the files go in the gmx folder, or a differnet folder?
Also, this nformation should denfinitley be added to the manual.
#8
Posted 01 October 2011 - 04:02 PM
#9
Posted 01 October 2011 - 04:03 PM
Create event (tried it in the beginnign of the web event as well, still doesn't work):
global.img = false;
sprite_crown = sprite_add("crown.png", 1, false, false, 0, 0);
Web event:
var name,spid,stat;
name = ds_map_find_value(async_load, "filename" );
spid = ds_map_find_value(async_load, "id" );
stat = ds_map_find_value(async_load, "status" );
if( stat<0 ){
show_message("Error loading "+name);
}else{
if( spid == sprite_crown ) global.img = true;
}
Draw event:
if (global.img == true) draw_sprite(sprite_crown, 0, 5,5);
crown.png is in the gmx folder (where the project file is) - is this the right place?
Thanks for your help.
#10
Posted 01 October 2011 - 04:13 PM
#11
Posted 01 October 2011 - 04:33 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











