HTML Target specific features

Monkey Targets Forums/HTML5/HTML Target specific features

Mauli(Posted 2014) [#1]
Hey guys,

I was wondering if there is a possibility to check what browser the user is using, similiary to getting the TARGET. My problem is that not all browser share the same support for audio codecs. I am using .wav as the format for my audio files, but unfortunately IE does not support .wav, so my idea was to check the browser in a preprocessor statement and load the audio file in a supported format.

My second question is about the focus of the canvas in html. I would like to pause the game and display a pause screen when the user clicks somewhere outside of the canvas so it looses its focus.

Since MonkeyX is about cross-platform support I suppose it wouldn't fit the concept to implement such features, so if there is some viable workaround I would be happy to hear from it :)

I appreciate every constructive answer :)

Greets


DruggedBunny(Posted 2014) [#2]
This seems to work -- it looks like the dom module now has to be imported via "Import dom.dom" where it used to be "Import dom"...

#If TARGET="html5"

	' HTML5 only!
	
	Import dom.dom
	
	Function PrintStuff ()
		Print document.URL
		Print window.location.hostname
		Print window.navigator.appName
		Print window.navigator.appVersion
		Print window.navigator.platform
		Print window.navigator.userAgent
	End

#Else

	Function PrintStuff ()
		Print "Not using HTML5!"
	End
	
#Endif

Function Main ()
	PrintStuff ()
End Function


You want window.navigator.userAgent here...

Not sure about the second question -- by default, clicking outside should auto-suspend, and you should be able to detect it by adding Method OnSuspend () and OnResume () to your App class, but I don't think you can draw at that time...


Mauli(Posted 2014) [#3]
Thanks for the reply :)

I did implement a method to parse for the browser, that is used, although I am not sure if this is the right or an elegant solution but at least it works:



The OnSuspend() and OnResume() methods I now use for measuring the "timeout" so I get the right deltaTime after resuming, to prohibit the timeout from corrupting my logic.

So thanks DruggedBunny, your answer was very helpful :)


DruggedBunny(Posted 2014) [#4]
Woo-hoo!


Yoda(Posted 2014) [#5]
I did this (can be found somewhere else in the forum):

		browser = GetBrowserName()
		website = GetCurrentURL()
		soundextension=".ogg"
		If browser="Safari" Or browser.StartsWith("Internet") Then soundextension=".mp3"

		soundclick = LoadSound("sound-click"+soundextension)
		soundconfirm = LoadSound("sound-confirm"+soundextension)