Does Javascript let io games know if it is on a phone or desktop?

beavoid
beavoid used Ask the Experts™
on
Hi
I think for my io game in javascript, it would help my game object layout if I knew if the game was being played on a phone or desktop.
What is the best way to do this?
Also. . . Clear the canvas for a game loop efficiently? Is Javascript rendering super-fast?
...and then place my game objects appropriately?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ron MalmsteadInformation Services Manager

Commented:
Yes it is possible.

See this question on stackoverflow.com
Detect device in Jquery/javascript

Typically however, the detection is used for browser code compatibility, rather than adjusting items for screen size.  The device itself is usually responsible for scaling images and other media to fit the screen... but there are some circumstances where you would need to set limits, or prevent screen rotation.  Notice most games will not rotate on a screen when the device is turned vertical...or horizontal... this is usually hard coded as landscape or portrait layout.  I have no idea how they do that however.  If you figure that part out let me know because I need it too.  lol.
beavoidSelf Employed

Author

Commented:
Is it a strategy to test the screen dimensions given and proceed from there?

Thanks
beavoidSelf Employed

Author

Commented:
Thanks

Does the Javascript code receive data members of screenWidth and screenHeight? It does in HTML5?
That would be convenient. Does phone/tablet JS receive the dimensions?

Would you advise me to write in .js files or HTML5, if I intend to focus on Device games.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Ron MalmsteadInformation Services Manager

Commented:
My advice would be to write the code in whatever language you are most proficient, and test on one device, until you have acceptable results.  Then use the device and browser detection code to make the necessary changes for compatibility ..testing on other devices.

HTML5 is native webpage rendering browser code, while js is more for interactive scripting and client side processing of page elements ... chances are you will employ a lot of both in making a browser game, but your engine will be java reliant.

Again the device and browser are primarily responsible for scaling elements to screen size.  If it wasn’t designed this way you would literally need entirely separate code for every device that could exist.  Iphone for example has differnet versions with different screen sizes and thousands of android devices have differing sizes as well.

For now.. concentrate on the game engine and playability.. because everything else can be modified through style{} manipulation for different devices and browsers later.
beavoidSelf Employed

Author

Commented:
Thanks
I am most proficient in Java games, esp game authoritative servers after mucho EE assistance. (thanks legends) I wrote a working RTS server, with UDP packet firing for increased server speed.
That is not possible in browsers (UDP is not supported)  I have access to a committed private server: non VPS
Anyway, I am keen on the idea of writing my game in Java.
What do you know about converting it afterwards to iPhone, browser, etc.

Should I just make it and ask questions later? TCP/IP clients and server...
Thanks
Ron MalmsteadInformation Services Manager

Commented:
Actually that is not true.

WebRTC uses UDP at the transport layer.  ICE implementation can be used for traversing NAT and firewalls as well.

https://en.m.wikipedia.org/wiki/WebRTC

It is a browser based protocol used for real-time communications..like video, voip, and yes... games.

This article explains better than the wiki - https://hpbn.co/webrtc/

This is large undertaking, but if you can implement it, you will end up with a realtime game engine using UDP transport.

And yes, I would just start making it with your basic plan/roadmap, and cross the code barriers as they come.

As far as converting to an actual installable app, I’m afraid I can’t offer much help there.

One thing I would definitely recommend, is to do a little research and make sure you aren't reinventing the wheel so to speak.  There are already browser based game engines you may be able to implement more quickly.
beavoidSelf Employed

Author

Commented:
Awesome
What dimensions should I give my JFrame? 1000's or 100's?

Thanks
Ron MalmsteadInformation Services Manager

Commented:
For dimensions it would depend I guess on whether or not you want it to be full screen or a ratio thereof.

https://alvinalexander.com/java/jframe-size-example-screen
Information Services Manager
Commented:
Just like any broswer element you have the option to let the device and browser scale items automatically or you can set them static...or minimim size .. maximim size.. and also initial size.  So for example a static setting will chop part the frame if the browser is resized smaller by the user.  An auto scenario... the frame would shrink and still show the entire frame with elements also shrunk to fit unless child elements are set static in which case it will chop those.

It all comes down to styling parameters you set for elements and the frame parent as well.  When I’m making web pages I tend to not set these things initially.. stylings is usually the very last thing I do.  Concentrate on functionality first and everything else is appearance and behaviour.
beavoidSelf Employed

Author

Commented:
Thanks

Now I don't have 4to waste any time thinking on device issues!
Ron MalmsteadInformation Services Manager

Commented:
Good luck man.  👌

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial