I've got a basic game written, but cannot place objects correctly depending on screen resolution.
For example, I'd like to position the Score in the top-left corner of the screen.
My logical dimensions are 320x480
This does not work:
http://appcodingeasy.com/Gideros-Mobile/Ignore-Automatic-Screen-Scaling-when-positioning-objectsIf I set the resolution of the Player to iPhone 5 Retina, the top left corner is 0,-44. However, during testing I discovered the top of the screen is -37, not -44 so the Score does not show up.
scoreText = TextField.new(nil, "Score: " .. score)
scoreText:setPosition(-dx,-dy)
stage:addChild(scoreText) |
In fact, it doesn't seem to matter what resolution for simulating, the Score does not show.
Comments
http://BlueBilby.com/
https://play.google.com/store/apps/developer?id=My+name+is+Originality
This will not display text at 0.
iPhone 5 retina: 1136 * 0.1 = 113.6
This will also not display the score at the top of the screen. (-47)
http://BlueBilby.com/
https://play.google.com/store/apps/developer?id=My+name+is+Originality
application:getLogicalHeight() or width will always return 480 and 320 so i think they can not do the job
Likes: WauloK
http://BlueBilby.com/
coooooool
[edit : sequence broken]
http://BlueBilby.com/
so it is a anchor point issue right? you need to position textfield from the bottomLeft
http://BlueBilby.com/
try this code
Likes: fxone, WauloK
Likes: hgvyas123
https://play.google.com/store/apps/developer?id=My+name+is+Originality
http://BlueBilby.com/
http://BlueBilby.com/
It's basically the same idea @hgvyas123 said, but when I forget off the top of my head I always end up checking back to that for reference.
Have you tried to get the textWidth, so you can use DEVICE_WIDTH - textWith which should make it right justified.
There was another discussion with Atilim, where because Gideros uses baseline text, it can affect the positioning a little in comparison to others that position the text from the top instead, like a bitmap.
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
Logical will never line up on multiple resolutions where you want it to, unless you scale everything then it looks crap.
http://BlueBilby.com/
I then set the close button position using:<pre escaped='true' lang=lua>self.closeBtn:setPosition(760+closeBtnDx,40-closeBtnDy)
I actually had lots of other offset variables in as well to position other items differently according to the aspect ratio so that things looked better on the different screens.
Pete
Likes: WauloK
application:setLogicalDimensions(application:getDeviceWidth(),pplication:getDeviceHeight());
This will get the device resolution and set this on propreties of your project.
When you use setposition this funcion use the refecere of logical dimension of you project propreties.
this function above change this value to the correct resolution of you device.
It shouldn't be this hard
http://BlueBilby.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
In this instance, as well as having adjustments for the close button, I also had a number of other variables for adjusting other items - I guess these could all be in tables as well or could they all somehow be in one table?
I guess I will write up an article that can help you understand this, will post the link here soon.
Likes: hgvyas123
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
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
The thing I noticed when reading it that I'd not spotted before is that it works for specific aspect ratios. My original if...then version used greater than and less than conditions to pick up not just the specific values but also the in between aspect ratios so that it would get close for devices that had odd screen ratios (e.g. the Archos 70 has a nominal 800x480 screen but uses part of the screen for the home, menu and back buttons so the width is nearer 770 even though the height is 480 (landscape here). Would it be possible to do something like that using tables?
I did notice that you used <=, with tables it is a Key Value pair, or dictionary objects as it is called. In a dictionary we have a word not a range or words (alternative spellings) so you cannot really use ranges.
In the case of resolutions which is the main concern, the way would be to use the resolutions as HxW --> 800x480 using the application:getDeviceHeight() .. "x" .. application:getDeviceWidth() which can be an entry in the table. This could be more accurate or important as there could be an android table with a larger resolution but an aspect ratio of x, but the positions for the same aspect on a smaller device would not b be the same. Simple things like fontSize could change too. Hope I managed to explain that.
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