How can I get the device Width and Height?

About Monkey 2 Forums Monkey 2 Programming Help How can I get the device Width and Height?

This topic contains 15 replies, has 7 voices, and was last updated by  arpie 3 months, 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #13416

    APC
    Participant

    On Monkey1 I was able to get the Device Width and Height using DeviceWidht() or DeviceHeight()

    I did use the code below to get the device width and height from Monke2, and tested on Android and iOS.

    It gets the android screen sizes but not from iOS.

    How can I get the device w x h before setting my app Window Widht and Height?

    #13417

    Hezkore
    Participant

    I haven’t done any iOS coding in Monkey2 so I’m not sure.
    But I do know there’s App.DesktopSize so maybe give that a go?

    #13420

    Diffrenzy
    Keymaster

    @apc : can you explain why you need it?

    Code like the one below will give you a fullscreen window on IOS, and then you have access to Width and Height and stuff like

    ´Method OnLayout()
    Print Self.RenderRect)
    End Method

    ´

    #13422

    APC
    Participant

    @Hezcore: Thank you for your suggestion I will give it a try.

    @Diffrenzy: I want my app to look the same on devices with different resolution. I build my sprite sheets with high resolution images , than based on the screen resolution I scale down the images, so they look the same on all screens. That is how I did in Monkey 1.

    I would like to hear from @Planiax, @Diddy and other people how do they handle iOS and Android screen resolution with Monkey 2?

    Also some apps I have to detect the screen rotation, I am using the OnMeasure() to detect the orientation change, as it is posted above.

    I have spent a lot o time searching this web site and Github to find answers and get my apps going. But I spent more time with trial and error than developing my app.

    #13423

    Diffrenzy
    Keymaster

    I build my images based on resolution too, why can’t you do that in New() ?

     

    [EDIT]: Testing this on IOS now, and I can’t seem to make my Ipad 3 go beyond 1024 x 768?

    [EDIT2]: Is this the reason: https://stackoverflow.com/questions/11342081/how-to-setup-xcode-project-for-retina

    [EDIT3] : On iPhone 6 i get 568 x 320 , hardware res is 750×1334

     

    #13424

    secondgear
    Participant

    Could it be that your XCode project doesn’t have launch screen images for your device resolution?

    https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/

    From what I understand, iOS uses them to determine if your app supports native resolution of the device, and if not, the OS will scale your app (and hence the app will get some scaled width and height info instead of the actual pixels).

    #13425

    Diffrenzy
    Keymaster

    I’ve made progress but iPhone is still messed up.

    Look at this screenshot, it should be 1364 x 750 and centered.

    Adding the HighDPI flag (thanks Ethernaut ) gives higher res.

    Adding the lauchimages (thanks skid and secondgear)  (I used https://github.com/raphaelhanneken/Iconizer/releases ) makes the iPad 3 goto 2048  x 1536 with is correct.

    Android phone goes to 1920 x 1080 correctly.

     

     

    #13445

    APC
    Participant

    Thanks Deffrenzy,

    I got the same results on iPhone and Android.

    I never heard about these Windows settings ” HighDPI and Fullscreen” for mobile devices !

    Is there a place in this forum that is specific about iOS and Android?

    There is a question that remains, How do I detect the device screen size before I can set the Windows size?

    #13448

    Diffrenzy
    Keymaster

    @apc : My tests show two important things:

    You can’t rely on app.DesktopSize on mobile, because at least on iPhone it returns a wrong value.  only non retina size.

    after Super.New( title,width,height,flags ) you can use Width and Height values, so that is a safe place to init graphics.

    There is still 1 problem remaining: I have found out why I am getting the 1136×640 window: If the iphone has Settings, display & Brightness, “Display Zoom.” turned on,  Monkey/SDL does something wrong.

    [EDIT]: Posted an issue on github : https://github.com/blitz-research/monkey2/issues/331

    This runs well for me (but does not solve the zoom issue)

    PS: I only think you need the HighDPI and Fullscreen flags.

    #13449

    Mark Sibly
    Keymaster

    Its shouldn’t matter what you set window size to, as it will always be maximised. Just check Width and Height after creating window/

    #13450

    Diffrenzy
    Keymaster
    #13469

    Mark Sibly
    Keymaster

    Should I ditch the HighDPI flag? Should it just always be ‘on’? It would save a lot of headaches as DesktopSize could returned scaled/physical/retina size, and DPI/retina handling could all be done internally etc.

    #13472

    Diffrenzy
    Keymaster

    Yes, to me the HighDPI  is just confusing, so it can go away.

    If setting it to always on, makes App.DesktopSize return the correct pixel dimensions, that is even better.

    Android already does high resolutions without a concept of “scaled down/half res” so it would also make things more consistent.

    #13473

    Ethernaut
    Participant

    I run into a lot of performance issues with HighDPI on when maximizing or going full screen. If it goes away, it would be nice to have some sort of “Half-resolution” mode, or a fill mode that lets you specify the vertical resolution (and adapts the horizontal automatically).

    We can always render to texture with whatever resolution  you want, but it’s kinda bureaucratic for small projects / quick tests.

    #13475

    Diffrenzy
    Keymaster

    In addition to Ethernaut’s thoughts I can say that after searching the net for solutions to the  problem above, I realize that HighDPI is a desktop setting too, targeting Windows and Mac desktops, so it might be important for some uses.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.