GM4HTML5 FAQ

= GameMaker:HTML5 frequently asked questions =

To help us streamline the feedback for bugs, and general questions developers have about GameMaker:HTML5, I have started to put together this FAQ. As more common issues arise, I'll start to add to this as time goes on.

Questions

 * 1) Text/Sprites/Backgrounds do not colour correctly when I double click on the index.html file Image tinting isn't actually available in HTML5, so we cheat a little and copy the image, lock it's pixels, and re-colour it using JavaScript code to tint every pixel by hand. We do cheat a little in order to help speed things up, but being able to get at an images bits is vital for this to work. However...certain browsers (like Firefox and Chrome) have security settings that don't let us modify images when they have been loaded from a local source, they deem this as a security threat and just don't allow it. This means we're stuck using the original image, and on things like fonts, that means a white font (you can't re-colour black!). There is nothing we can do about this, HTML5 content that does this MUST be loaded via a web server, and this is why GameMaker:HTML5 comes with a web server built in for you to view your games. So rather than clicking on the file, you really should view it via the built in web server, or it will probably not look correct.  Hint: you can also use Apache server like WAMPP to run from your localhost server without publishing to web
 * 2) The game is running very slowly in IE, and crashes Chrome! This is probably because your using extensive colour tinting for lots of sprites. HTML5 does not allow for full colour blending, so when you try to draw a sprite using a colour, we create a copy of the sprite and cache it. However, the cache is pretty small (only 4 images) so if you have many colours, this will cause them to be created every time you draw them, and this will burn memory at a ferocious rate! Chrome doesn't like this at all! It's garbage collection system simply fails and it dies a horrible death. We have however added a couple of new commands to help you manage your colour tinting better; sprite_set_cache_size and sprite_set_cache_size_ext give you fine control over the sizes of the cache for each sprite/image, and should allow you to colour whatever you need to. Be warned however, each sprite you colour will use memory, so you probably shouldn't just set all them to large numbers as you'll be back to having bad things happen. This also causes issues for blending fonts, so care must be taken with them as well.
 * 3) Text/Sprites don't use the 4 colours I provide when drawing. HTML5 does not allow for full colour blending, or vertex colouring as it's know in D3D. This means we simply can not draw with 4 point colouring on HTML5. While we could simulate it, it would burn memory and processor power to do it. So we have taken the decision not to support 4 point vertex colouring in HTML5. When WebGL appears, it will be able to support it, but WebGL will not be available on all browsers, so you should use with care.
 * 4) Sprites are not showing in the correct order, their depth seems different from the windows version. This is a new requirement going forward. In the past, instances where displayed in an odd creation based order; not quite creation order... but object->instance->object creation order, and this in turn has some odd knock-on effects. As of GameMaker:HTML5, we now set the rule that if it's at the same depth, then order is not guaranteed. If you really want an instance in front or behind another one, then you should now set the object/instance depth correctly so that it definitely IS in front or behind. This allows us to optimise the rendering path much more efficiently, and gives a very clear system that everyone knows, and can follow.
 * 5) When I delete an object/sprite/room/path/timeline/etc. the file is not erased from the disk. This is the default behavour as it's designed to work properly with source control systems. Most source control systems don't like it if you just delete things without telling it first, so we can no longer just erase them when we like. if you want to purge the directory of all unused files, you can export the project to a .GMZ, and then re-import it. This packages everything the project uses into a single archive, and one of it's many uses is that you can use it to reconstruct a clean version later. NOTE: There is now an option in the preferences to delete the file from disk, but it is OFF by default so that there is no issue with version control software. Selecting this option will tell GameMaker:HTML5 to delete the resource once you have deleted it from the project.
 * 6) message boxes aren't working in HTML5 Unlike windows, HTML5 message boxes are not skinable, they are FIXED 2 2 buttons which say OK and CANCEL. You can't set the font, background, colour or number of buttons. They are very limited. Normally, we would take over the game loop and write the message box our self, but browsers don't let you do that. This means to keep the same mechanic, we're stuck using the very simple, and basic message boxes that come with each browser. This said.... standard message boxes really aren't a good game play experience, and if you need a message box, you should really write one yourself so that it pops up with a much better look and feel.
 * 7) Loading scripts and execute_string/execute_file These are no longer supported. 1st, to be able to load a GML script into JavaScript would require a GML compiler written in JavaScript (which is what the windows runner has). We took the decision not to allow this for a few reasons. 1st, it would significantly increase the amount of code in the runner, and push up the size of each game. 2nd, the amount of work involved in rewriting the parser+compiler into JavaScript was really too much for our timeframe. 3rd, you should really never need this feature. All commercial games get by without this, as do most apps. This is a pretty reassuring statistic that removal of it isn't the end of the world. If you need to load code, you can still do that with your own JavaScript extensions.
 * 8) Changing rooms does not change the size of the screen/canvas This is by design. First, we expect HTML5 games to go onto websites, and as such they will have web pages designed around them, or they will be placed into  spaces set aside for them. For this reason, we believe having the canvas changing size and breaking web page layouts is a bad idea. We have also taken the choice to allow scaling of the game by changing the index file. This is to allow better integration with web sites, in particular the various games portals which may have very specific requirements for sizes of games. This allows you (or them) to change the size of the final game, without having the source, or needing to recompile the actual game. Lastly... changing the size of the game play area, is a terrible user experience, and one which will be going away as we go forward from GameMaker:HTML5 to GameMaker:Studio and GameMaker9, so it's something you'll need to get used to.  You can change the size ofthe canvas, but you have to do in MANUALLY. See this GMC topic about resizing.
 * 9) Treat uninitialized as 0 option no longer exists. Due to the way HTML5 works, this is simply no longer works. On top of that, this is simply bad practise. It hides nasty bugs and will (not if) cause you issues further down the line. Going forward we will be removing this completely from all versions of GameMaker, thereby forcing you to create and initialise the variable before you use it. This is good practice anyway, and not only gets you used to thinking about variable usage (and what is local/global/instance based), but how much memory your using for these variables as well. On top of this, it will save you time in the long run, particually when you debug as you KNOW what variables exists, you will no longer "miss-type" it and wonder why things aren't working, and it'll let us optimise things even further.
 * 10) Game doesn't start/show up in the browser. Make sure none of your assets have a dash (-) in their name, especially Objects.  For some reason this will prevent your project to start in the browser.
 * 11) Functions like variable_global_set, variable_global_exists or variable_local_array_set don't exist. GameMaker HTML5 converts directly into Javascript, and to make it as fast as possible we use actual variables. In order to implement these functions we would have do a function call for every variable access, or dynamically compile a bit of javascript which would test for the existence of the variable. Both of these would seriously hamper the performance. You should never really need these functions, but if for some reason you do, you're far better using something like a ds_map as this will give a fast lookup for only the variables you need.