Quick Links: Gideros Home | Download Gideros | Developer Guide
Different aspect ratios in letterbox mode: calculate coords of screen corners?
  • snooks +1 -1
    Member
    I am displaying a TileMap on screen and notice that with different aspect ratios than the logical dimensions that there is a bar at the left hand side of the screen. I can manually offset everything to account for this, but would like to calculate what the coordinates are for the bottom left and bottom right corners of the screen in logical pixels at runtime to do this automatically and know what the margins are and exactly what's happening on the user's screen.

    I see we have:

    ContentWidth
    ContentHeight
    LogicalWidth
    LogicalHeight
    DeviceWidth
    DeviceHeight
    LogicalScaleX
    LogicalScaleY

    But I'm a bit brain dead at the moment/always so can't see what the relationship is. Could anybody please provide details of how to best deal with this?

    Thanks in advance!

  • hgy29hgy29 +1 -1 (+1 / -0 )
    Maintainer Accepted Answer
    Personnaly I do:
    local lox,loy=application:getLogicalTranslateX(),application:getLogicalTranslateY()
    local lsx,lsy=application:getLogicalScaleX(),application:getLogicalScaleY()
    local cw,ch=application:getContentWidth(),application:getContentHeight()
    local scx,scy,scw,sch=-lox/lsx,-loy/lsy,cw+lox/lsx*2,ch+loy/lsy*2


    Which gives scx,scy: the screen origin in logical coordinates and scw,sch: the screen size in logical coordinates

    Likes: totebo

  • antixantix +1 -1
    Member
    A tutorial on this stuff would be good, that covers fitting to screen as well :)
    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor
  • totebototebo +1 -1 (+2 / -0 )
    Member
    +1 for a tutorial, or even better, a simple project explaining screen resolutions. Gideros is great at it, with @2 and @3 sprites.

    Likes: antix, talis

    My Gideros games: www.totebo.com

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters