Hello, in my project I'm using Letterbox and relative positioning of objects in my scene and it works fine with different resolutions. For that I use the examples in the App Coding Easy blog.
But for a future app feature I would like to get a value, say, a 1000th of the current device screen width & height to position objects. But I don't seem to work it out.
A question related to this is the getDeviceWidth() function. It returns the correct values in output but it places the object roughly only two thirds of the expected position. What am I missing?
devicewidth = application:getDeviceHeight()
deviceheight = application:getDeviceWidth()
dx = application:getLogicalTranslateX() / application:getLogicalScaleX()
dy = application:getLogicalTranslateY() / application:getLogicalScaleY()
local blacksquare = Bitmap.new(Texture.new("images/blacksquare.png", true))
blacksquare:setAnchorPoint(0.5, 0.5)
blacksquare:setPosition(-dx + devicewidth, -dy + deviceheight) |
Example: for a iPhone 5 retina 1136x640 resolution (landscape), the object ends up at ca 758x427.
Thanks in advance
thomas
Comments
If that is what you want here is the code I wrote for you.
first of all I replaced the deviceWidth and deviceHeight with getContentWidth and getContentHeight.
And because you use anchor point (0.5,0.5) you should subtract the half of your sprites width and height.
those are the other corner positions
Upper left corner:
I thought getDeviceHeight() would seem to help, at least as I understand the reference, but apparently it returns different results in output and on the screen. Does anyone know the practical use of getDeviceHeight/Width?
You could make a wrapper to setPosition function, or make your own, setUnits function which takes into consideration dx and dy values, like from -dx and -dy to contentWidth+dx and contentHeight+dy
What about getDeviceHeight() and getDeviceWidth? Any usability examples on that?