Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Screen/Device height and width — Gideros Forum

Screen/Device height and width

gyrospgyrosp Member
edited November 2012 in General questions
And another question ;):

How do I get the width and heigt of the screen/device?

In the docs I've found Application:getDeviceWidth().

But when I use it I get the error
Test.lua:104: calling 'getDeviceWidth' on bad self (Application expected, got table)
stack traceback:
this is the corresponding part of my code:
if (self.PosX > Application:getDeviceWidth()) then
	self.PosX = 0
end

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited November 2012
    Application is a class name, whereas application is the global predefined instance of Application class.
    Thus:
    if (self.PosX > application:getDeviceWidth()) then
    	self.PosX = 0
    end
    And if you are going to use some sort of automatic scaling, I would suggest using getContentWidth and not device width. ;)

    http://appcodingeasy.com/Gideros-Mobile/Difference-between-content-logical-and-device-dimensions-in-Gideros-Mobile
  • :-S ... sometimes it's so easy :(... thanks a lot :D

    Unfortunately getDeviceWidth and getDeviceHeight do not work as I expected with the player
    	print(application:getContentWidth())
    	print(application:getContentHeight())
    generates following output
    320
    480
    My player settings are 768x1024(iPad) and the orientation is Portrait.
    Should the value of getContentWidth 768 and getContentHeight 1024?
  • OZAppsOZApps Guru
    Accepted Answer
    @gyrosp, the settings that show up with
    getDeviceWidth
    and
    getDeviceHeight
    are what are set in your player device.

    However the
    logicalHeight
    and
    logicalWidth
    return the settings as per the Project. So to get the results of 768x1024, you need the getDeviceWidth and getDeviceHeight not contentHeight and contentWidth (which could be scaled based on your project settings).

    Likes: gyrosp

    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
    +1 -1 (+1 / -0 )Share on Facebook
  • @OZApps
    Ok, I get it and it works now ;).

    But what are the right project settings if I want to create a mulitplatform/multidevice app? Does it matter at all?
  • Thanks for the link, I'll take a look at it :D
Sign In or Register to comment.