Set focus on iFrame when game loads

Get help using Construct 2

Post » Sat May 05, 2012 4:37 pm

If you publish to Kongregate, the game doesn't have focus when the page loads. The user has to click the iFrame to give focus to the game. This is not a good user experience.

How to make the game get focus when the frame has finished loading?

Thanks.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sun May 06, 2012 1:36 am

I don't know if Kongregate would allow it or not, but it is possible to emulate a click event with jquery $.click, also it has $.focus which might work.

So something like

$(window).on('load',function(){
$('iframe').click();
})

or

$(window).on('load', function(){
$('iframe').focus();
})

might work, but i'm just guessing here.
B
10
S
5
G
1
Posts: 37
Reputation: 1,631

Post » Mon May 14, 2012 10:49 pm

Hey Geo,

What do you mean by focus?

When I view my game at Kongregate. Apart from the advert that pops up sometime, I don't have to click on the game for it to start or register my 'mouse over' commands.

I point the url iframe to a privately hosted url (not the Scirra Arcade).
B
85
S
31
G
14
Posts: 106
Reputation: 16,440

Post » Tue May 15, 2012 11:44 am

Thanks for the jquery tips, I might try them on the next game if it will be an issue; I won't update the existing game as it would be too much overhead to add the jquery code.

@Andeming your game doesn't get focus either, but because it's played with the mouse it's not an issue - it just gets focus on the first mouse click.

My game was keyboard only and there's some issues with it - users have to click the iframe first before the game gets the keyboard input.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Tue May 15, 2012 2:25 pm

We have the same problem on our Arcade - I don't think there's a good way around it, other than to just have a title screen saying "Click to continue". I think most users are used to clicking inside a window to give it focus.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue May 15, 2012 3:16 pm

I didn't tried it, but you can have an out-of-view textbox, inside the iframe (but out of the viewport). If that widget has the focus, then the focus is given to the iframe enclosing it.
B
33
S
9
G
6
Posts: 709
Reputation: 6,704


Return to How do I....?

Who is online

Users browsing this forum: benajad, Braus, R0J0hound, shinkan and 24 guests