00:00
00:00
3p0ch
If you like hard games try my Daxolissian System series

plasmid @3p0ch

Cat

Scientist

Read the manual & try stuff

So Cal

Joined on 2/13/10

Level:
13
Exp Points:
1,622 / 1,880
Exp Rank:
38,652
Vote Power:
5.47 votes
Audio Scouts
1
Rank:
Portal Security
Global Rank:
23,939
Blams:
50
Saves:
367
B/P Bonus:
8%
Whistle:
Normal
Medals:
4,584
Supporter:
3y 1m 21d

Having to click the game to give it focus before playing? Now a thing of the past!!

Posted by 3p0ch - January 31st, 2021


Ok so I know it's a pretty minor thing, but I hate the fact that you have to click the game canvas to give it focus before you can start playing. It turns out that it's not actually necessary though, you can program your game so it automatically wrests the focus into its clutches after it's loaded and flips the bird at the main browser window.


In Godot I did it with this code

	if OS.has_feature('JavaScript'):
		JavaScript.eval("document.getElementById(\"canvas\").focus();")

and in most other game engines if you can run JavaScript (see this post for an example of how to run JavaScript from Unity) then you can do this by looking through the .html file that your engine generates for an element similar to the "canvas" element that Godot makes and use its ID in the getElementById().focus() call.


I also did it in HaxeFlixel where it's even easier, just slap this code in

Browser.window.focus();

I put it in the Main.hx file's new() function just before the addChild(new FlxGame)


1

Comments

Comments ain't a thing here.