SDK control the game from outside the document.

Discussion and feedback on Construct 2

Post » Mon Jan 28, 2013 7:45 pm

Hi guys,

I'm new to construct but I'm already amazed by it's simplicity and I feel like I'm going to enjoy it.

I created my first game and I displayed it inside an iframe on my website.

I would like to know if it's possible to use the SDK to reload the game from my website.

So I want to access the content of the iframe and then call a function that will reload the game.

Thanks in advance for your time and patience.

Best,

J.
B
6
S
1
G
3
Posts: 9
Reputation: 2,325

Post » Tue Jan 29, 2013 3:17 am

Bit unsure what you're trying to accomplish but I'll take a crack:

If you want to refresh your game from within your iFrame, that's as simple as restart layout event, you can map this from everything from a collision to a key press.

Refreshing your game from outside the iFrame, via a text or image link is pretty simple: Your best bet is to simply refresh the whole page, which will reset the iFrame.

If you want to refresh the game without refreshing your web-page, in theory you could get creative with mouse overlapping collisions; with your game refreshing the layout whenever the mouse isn't within your iFrame: The practicality of this questionable though.

Finally, if your familiar with JS, you can use that refresh your frame, simply use this on a button on your parent page:

[CODE]<IFRAME id="frame1" src="http://www.example.com/" runat="server">


    <script type="text/javascript">
    function refreshiframe()
    {
        parent.frame1.location.href="http://www.example.com/"
    }
    </script>


<asp:Button ... OnClientClick="refreshiframe();" />[/CODE]

As always StackOverflow is your friend: http://stackoverflow.com/questions/2064850/how-to-refresh-an-iframe-using-javascript

I'm pretty sure you can refresh an iFrame simply in HTML, though I've never tried, doubtless someone knows!
B
49
S
14
G
3
Posts: 540
Reputation: 5,611

Post » Tue Jan 29, 2013 7:52 am

@Mr E Bear : thank you for your kind answer.

Is it possible for an external button (not in the iframe) to call an action inside the game (canvas).

Like changing of layout for example.


Thanks again for both your time and patience.

J.
B
6
S
1
G
3
Posts: 9
Reputation: 2,325

Post » Tue Jan 29, 2013 8:15 am

For the reference, reloading the iframe with jquery :

[code]$( '#iframe' ).attr( 'src', function ( i, val ) { return val; });[/code]
B
6
S
1
G
3
Posts: 9
Reputation: 2,325

Post » Tue Jan 29, 2013 12:45 pm

This type of thing is suitable for the Javascript SDK, since you have to code the parent page Javascript anyway.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,564

Post » Sat Jul 13, 2013 10:07 pm

Hi I have the same need, I am building a serie of games and all the games have the same GUI, the problem today is if i like to make a change in the GUI i need to enter each game, make the change and export it.

so i would like to make the GUI in HTML with its own logic, and with it control the game states like pause, help, congratulation message and points.

for this i need to do a plugin with the Javascript SDK or is there a wahy to controling and accesig somo variables and states of the game from an external javascript?

thanks
B
8
S
4
Posts: 49
Reputation: 1,199


Return to Construct 2 General

Who is online

Users browsing this forum: andreyin, Eisenhans and 12 guests