How to Create Multi-Room Layouts For a 2D Game Using Arrays

4

Index

Stats

1,222 visits, 3,697 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

You may think that the Array would be something which the game would inherently have access to, but it is not. The Array is a project file, not a game file (unlike music). What this means is that the array exists within the entire game's programming but not within the game loop. In other words, it comes with the game but is not actually part of the game...

UNTIL, you add the Ajax plugin!

Ajax is used to retrieve files from outside the game (either the Internet or inside the project files). In this case, we can use it to give our game loop the data involving the array. But before we can do that, we need to add an Array object. We have already created the data for the array; now we just need a game-accessible place to put it and a way to find that data and actually put it there.

In any layout, add both the Array object and the Ajax plugin. For convenience, this can be the spawn layout, but it does not have to be.

Next, go into your Event Sheet (probably called Event sheet 1 unless you renamed it--you will only need one event sheet). Add the "System - On start of layout" trigger at the beginning. Then add the AJAX action "Request project file". Add the tag "rooms" in the first field and choose your array from the second. Now the game actually has access to all the data from your rooms array. Hit Done.

Next, add the "Ajax - On completed" trigger. This triggers any time Ajax finishes a request. Add the tag "rooms" to the tag field just like you did in the "Request project file" action. This makes it so that it only triggers when the request with the same tag is completed. This is technically unnecessary since this is the only thing we are using Ajax for, but with programming it's always good to be very, very specific. Make sure you spell both tags the same, otherwise the game won't realize that Ajax has completed the request.

Now, in the "On completed" trigger, add the Array action "Load". Then, in the JSON field for that action, write "Ajax.LastData". What this does is make it so that the Array game object receives the last thing Ajax received, which is the Array project file. In other words, both Ajax and Array are game objects, but only Ajax can access data that isn't a game file. So Ajax asks the project for all the data from the Array project file, and when it has received it, it gives the data to the Array game object. Now, the game loop can access all data relating to the array.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!