Jump to content


Photo

...so how do we use the web event, exactly?


  • Please log in to reply
10 replies to this topic

#1 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 30 September 2011 - 09:32 PM

Hi, Can someone give me a small example of using the web event, because there us nothing in the manual about it, and nobody seems to know.

Many thanks, please help because I really need this feature for my game.
  • 0

#2 JonathanPzone

JonathanPzone

    GMC Member

  • GMC Member
  • 1199 posts
  • Version:GM:Studio

Posted 30 September 2011 - 09:40 PM

It's in the manual.

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.
  • 0

#3 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

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.
  • 0

#4 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 01 October 2011 - 09:06 AM

I know what it does, but there is no information in the manual about how to actually use it.
Nobody seems to know.
  • 0

#5 BlaXun

BlaXun

    Slime Online Creator

  • GMC Member
  • 2616 posts
  • Version:GM:Studio

Posted 01 October 2011 - 09:10 AM

Dont you just use the sprite_add / background_add / sound_add and this will start the download for that ressource in the background.
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.
  • 0

#6

  • Guests

Posted 01 October 2011 - 09:43 AM

So... the web. It's big. I mean REALLY big.... you may think it's a long way to the shops but that's just peanuts to the web.... etc.

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 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 01 October 2011 - 03:47 PM

Awesome, thanks!
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.
  • 0

#8

  • Guests

Posted 01 October 2011 - 04:02 PM

You add the files to the project in the "included file" section, and these are then copied for you in the the output folder.

#9 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 01 October 2011 - 04:03 PM

Ok, i have a problem with my code:

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.
  • 0

#10

  • Guests

Posted 01 October 2011 - 04:13 PM

see previous response :biggrin:

#11 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 01 October 2011 - 04:33 PM

sorry, that post hadn't loaded for some insane reason, even after refreshing just before posting
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users