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

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
LVL 1
beavoidSelf EmployedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ron MalmsteadInformation Services ManagerCommented:
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 EmployedAuthor Commented:
Is it a strategy to test the screen dimensions given and proceed from there?

Thanks
beavoidSelf EmployedAuthor 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.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Ron MalmsteadInformation Services ManagerCommented:
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 EmployedAuthor 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 ManagerCommented:
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 EmployedAuthor Commented:
Awesome
What dimensions should I give my JFrame? 1000's or 100's?

Thanks
Ron MalmsteadInformation Services ManagerCommented:
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
Ron MalmsteadInformation Services ManagerCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beavoidSelf EmployedAuthor Commented:
Thanks

Now I don't have 4to waste any time thinking on device issues!
Ron MalmsteadInformation Services ManagerCommented:
Good luck man.  👌
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.