Getting the actual screen resolution

oripessach

  • *
  • Posts: 259
Hi,

I'm trying to write some code to position on-screen controls in a mobile game. I need to know the actual resolution of the screen, so I can figure out which portion of my game is actually displayed (because I don't want to put game controls off-screen.)

My game's scale mode is set to Scale to Fit (letterbox) and I made the game's resolution wide enough so that instead of getting black bars on the sides of my display, the edges are actually clipped. This works very well for me, since I make sure that the action is limited to the areas of the screen that are likely to be displayed on any device.

The problem is that I want the game controls (a D-pad and a couple of buttons) to be near the edges of the physical screen.

getScreenWidth() returns the game's resolution as set in the Game Settings->Settings->Display. This is of no use to me, obviously. I took a quick look at Engine.hx, but nothing jumped at me. How do I get any useful information about the device's screen dimensions?

Thanks!

Ori


mdotedot

  • Posts: 1649
Try this in a code-block (Flow - Advanced - code return block)

Code: [Select]
nme.system.Capabilities.screenResolutionX
(Note: you might need change nme into openfl in Stencyl 3.3 .. I'm on 3.2!)

This block can be used to fill an attribute for instance.
Change X to Y for the y-coordinate.

Hope this helps.

Best regards from
M.E.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

oripessach

  • *
  • Posts: 259
Yep, that does the trick - and you're right about changing nme to openfl, too. Thanks!