Trigger an event from within a site to a C2 game

0 favourites
  • 6 posts
From the Asset Store
A set of vector game assets contains ground tiles and several objects, used for creating platformer games
  • Hi community, in need of your assistance.

    CONCEPT:

    I am working on a series of educational games geared for children of various ages, each game contains multiple spritesheets that contain problems sets with various degree of difficulty. There will be an age selection window in the home page of the site before redirecting the user to any of the games. In practice, i would like for each game to change in difficulty based on the age group selected by the user.

    PROBLEM:

    If the age selection screen is hosted on a separate page/site, what would be the proper way to communicate with the hosted C2 game or how can i trigger an event from outside the game in order to change the difficulty level or in this case the spritesheet?

    If anybody can provide a solution or a simple example .CAPX, i would highly appreciate the assistance and let the community know.

    Thank you in advance...

  • There is an easy work around using invisible text boxes. Text boxes are actually created by the browser not construct2 yet the fine fellows at COnstruct allowed us to give them an ID which can be accessed by JS. So I used it as a messaging method between the two to control when construct was to be visible and not.

    Sorry for not including code, it is all on my work computer.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • maex900, that sounds like a simpler solution!.

    When you can, would you be able to provide a breakdown of how you achieved the request through JS or the .CAPX,

    I will credit you on this.

  • I will try to make a quick example, because I will probably forget if I don't do it immediately.

  • Type "Go" to trigger.

    Example:

    dl.dropboxusercontent.com/u/7900765/Example%20JS%20Connection/index.html

    Added to index.html:

    <input type="button" value="Search" onclick="doSomething();" />

         <script>

              doSomething(){

              element = document.getElementById(id);

                   element.text = "Go";

              }

         </script>

    capx:

    dl.dropboxusercontent.com/u/7900765/Example%20JS%20Connection/New%20project.caproj

  • You will find a problem once you get to making connections automatic not triggered, because browsers sometimes hate when there is code executing that wasn't user triggered. I can't remember my solution for that. If you run into that problem, you can hunt message me.

    I used this to create a project where we went from flash video to construct game back to flash video. amalgamedia.com

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)