Quick Links: Gideros Home | Download Gideros | Developer Guide
Pixels per inch
  • totebototebo +1 -1
    Member
    How do you get pixels per inch when using Application.LETTERBOX? I'd like to position something a certain (real-world) distance from the edge of the screen, regardless of size of display.
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Maintainer
    You should be able to retrieve device DPI and multiply or divide it by LogicalScale (X and Y)
  • totebototebo +1 -1
    Member
    Could't get it to work at all. Could someone try to post some actual code? It feels like nothing works! :)
    My Gideros games: www.totebo.com
  • totebototebo +1 -1
    Member
    I created a simple test, which also fails. Does this look right? I'm testing only the x axis at the moment to save time.
    -- Neither of these scale modes work
    --application:setScaleMode( "noScale" )
    application:setScaleMode( "letterbox" )
    local size = 5
    local sprite = Sprite.new()
    local pixel = Pixel.new( 0xff0000, 1, size, size )
    local x = -size/2
    local y = -size/2
    pixel:setPosition(x,y)
    sprite:addChild( pixel )
    stage:addChild( sprite )
    local top_left_x = -application:getLogicalTranslateX()/application:getLogicalScaleX()
    local top_left_y = -application:getLogicalTranslateY()/application:getLogicalScaleY()
    local dpi = application:getScreenDensity()
    local x = top_left_x + dpi/application:getLogicalScaleX()
    local y = top_left_y
    sprite:setPosition( x,y )
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Maintainer
    Try this:
    local sx,sy=application:getLogicalScaleX(),application:getLogicalScaleY()
    local ox,oy=application:getLogicalTranslateX(),application:getLogicalTranslateY()
    local dpi=application:getScreenDensity()
    local inchX,inchY=dpi/sx,dpi/sy
    local screenOriginX,screenOriginY=-ox/sx,-oy/sy
     
    local XdistanceInInches,YdistanceInInches=1,0.5
    local p=Pixel.new(0xFF0000,1,20,20)
    p:setPosition(screenOriginX+inchX*XdistanceInInches,screenOriginY+inchY*YdistanceInInches)
    stage:addChild(p)


    It will place the 20x20 box top/left corner at 1 inch from left screen border and 0.5 inch from top screen border, whatever your scale mode or device is.

    EDIT: yes, your code look fine :)
  • totebototebo +1 -1
    Member
    Thanks @hgy29! I tried your code above on an iPod 5th gen, an iPad Mini Retina and a Pixel XL. The dot appears in varying distances on all of them; the iPod and Pixel are roughly in the same place, but the iPad is way off in both directions.

    Their respective dpi's are:

    Pixel XL: 560
    iPad Mini Retina: 264
    iPod 5th gen: 326
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Maintainer
    I tried on my iPhone 6, and it worked ok. Could it be that your app is in landscape ?
  • totebototebo +1 -1
    Member
    It's a portrait app running on all devices. Did you test it on another device?
    My Gideros games: www.totebo.com
  • totebototebo +1 -1
    Member
    To be more precise, here are the real world dimensions of a "1 inch" square drawn with the code above:

    Pixel XL: 1.02x1.02 inches
    iPod Touch 5th gen: 1x1 inches
    iPad Mini retina: 0.8x0.8 inches
    Nexus 5: 1x1 inches
    Nexus 6: 1.1x1.1 inches

    Maybe the device dpi isn't an exact science?
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Maintainer
    Or maybe reported DPI is wrong for some devices ? you said your iPad Mini retina was 264 dpi, while apple specs say it is 326. And 264/326 is almost 0.8, coincidence ?
  • totebototebo +1 -1
    Member
    I think you're onto something. It's likely to be a hardware issue.

    I found this thread:
    http://stackoverflow.com/questions/13178186/how-can-i-detect-the-dpi-on-an-ipad-mini

    And:
    http://stackoverflow.com/questions/28573639/how-do-ruler-apps-stay-accurate-on-all-devices

    Looks like the only way to do it is to hard code the dpi per iOS device. Bummer.
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Maintainer
    Gideros uses the detection routine posted here: http://stackoverflow.com/questions/3860305/get-ppi-of-iphone-ipad-ipod-touch-at-runtime

    Comments in that thread confirm it doesn't work for iPad mini and maybe iphone6 plus, but there doesn't seem to be an universal solution yet, we have to resort on hardcoding them depending on the device type.
  • totebototebo +1 -1
    Member
    Oh that's great, so this could potentially be updated? Found this at the bottom of that thread which appears updated and comprehensive:

    https://github.com/lmirosevic/GBDeviceInfo

    Is that what we're using now?
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1 (+2 / -0 )
    Maintainer
    Yes, we can do something similar in gideros too.

    Likes: antix, totebo

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 Google Sign In with OpenID

In this Discussion

Top Posters