How to set layout according to url hash (#) at first load?

For developers using the Construct 2 Javascript SDK

Post » Sun Oct 25, 2015 12:18 am

Hi, this is my first post so I'd like to start by saying thank you to everyone who is involved in creating and maintaining this great piece of software.

I am trying to create a plugin that allows the app/game to navigate to a layout according to whats after the hash sign in the address (#), like:

That way you can access different parts of the game by url, so you can use the navigator arrows, history, bookmarks, etc... I think that way you could actually make really beautiful and modern websites in Construct.

I searched for something like that but didn't find anything (please correct me if I am blind and there's already something like this). Anyway, the way I am doing it, it is a very basic plugin (based on Ben Alman's hashchange jQuery plugin) and it is almost done: I can add the (global) object to my project and when I load the game in the browser and start changing the address, introducing the exact name of the layout after the hash (like #MyLayout) it correctly navigates to the layout. However, there is one thing that's driving me crazy:

How do I cause the game to go to a certain layout, from the runtime, when it first loads?

That's needed so that you can access specific parts of the game by address, like when you share a link. The most obvious approach was to set runtime.changelayout at instanceProto.onCreate but that didn't work. I also created a callback for the document load but that didn't work either.

If anyone has an answer to my question (in bold above) it will be very much appreciated. Once the plugin is done I would like to share it with everyone.

Posts: 1
Reputation: 177

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 2 guests