Understanding Scaling for different resolutions
Posted: Wed May 27, 2015 8:32 pm
Hey all,
I've been working for the past month or so on a small game that has not transitioned me to use the Love-Android port. One of the biggest challenges to me right now is the scaling of the game to fit the different resolutions of the different devices. I'm not sure if this is something I'm not understanding correctly, or if I'm just using the tools given to me incorrectly, or what it is. I'll try to be as detailed as possible below.
With Love-Android we get the function
Within Love2d, we also have the function
So i was hoping to do something increadibly simple, like this
So, looking at this, you can probably see what my problem is. When i run the game on my PC, it looks fine. All the circles are in the corners of the window, and they all move diagonally toward their opposite corners.
However, when i publish out the apk and run it on my phone (Samsung Galaxy Note 4) or one of my kids tablets (Nabi Dreamtab), the scaling does not work like I intend it to. Instead, for example, on my phone, the scale equals 4. In my head, this makes since since it's a smaller screen, the scale will need to increase. However, when it opens, all i can see is the circle that spawns in the top left corner, and nothing else. So it's like in theory it worked, the circle definitely got bigger, but everything else is now offscreen.
So it's like the "size" of everything scales, but so does the resolution? x, y coordinate? This is where i'm getting hung up and not understanding what is going on. Any help in this is greatly appreciated.
here are screenshots for references:
Screenshot from phone - https://love2d.org/imgmirrur/0TeOTYC.png
Screenshot from PC (what it should look like on phone) - https://love2d.org/imgmirrur/h1XX5uP.png
Attached is also the game.love file created with the code (sorry if it's a mess)
Thank you again for anyone that can assist in me understanding this
I've been working for the past month or so on a small game that has not transitioned me to use the Love-Android port. One of the biggest challenges to me right now is the scaling of the game to fit the different resolutions of the different devices. I'm not sure if this is something I'm not understanding correctly, or if I'm just using the tools given to me incorrectly, or what it is. I'll try to be as detailed as possible below.
With Love-Android we get the function
Code: Select all
love.window.getPixelScale()
Code: Select all
love.graphics.setScale(sx, sy)
Code: Select all
function love.load()
-- get scale factor
if love.system.getOS() == "Android" then
scale = love.window.getPixelScale()
else
scale = 1 -- set to one for pc version
end
--[[
code here to create 4 circles and set the x, y of each
to put them in the four corners of the screen
and store them in the circles table
--]]
end
function love.update(dt)
--[[
code here that will update the positions of the
circles to move them diagonally toward their
opposite corners
--]]
end
function love.draw()
-- draw the circles
love.graphics.push()
love.graphics.scale(scale, scale) -- set the scaling based on what we got in love.load
love.graphics.setColor(255, 255, 255)
for i, circle in ipairs(circles) do
love.graphics.circle("fill", circle.x, circle.y, circle.r)
end
love.graphics.pop()
end
So, looking at this, you can probably see what my problem is. When i run the game on my PC, it looks fine. All the circles are in the corners of the window, and they all move diagonally toward their opposite corners.
However, when i publish out the apk and run it on my phone (Samsung Galaxy Note 4) or one of my kids tablets (Nabi Dreamtab), the scaling does not work like I intend it to. Instead, for example, on my phone, the scale equals 4. In my head, this makes since since it's a smaller screen, the scale will need to increase. However, when it opens, all i can see is the circle that spawns in the top left corner, and nothing else. So it's like in theory it worked, the circle definitely got bigger, but everything else is now offscreen.
So it's like the "size" of everything scales, but so does the resolution? x, y coordinate? This is where i'm getting hung up and not understanding what is going on. Any help in this is greatly appreciated.
here are screenshots for references:
Screenshot from phone - https://love2d.org/imgmirrur/0TeOTYC.png
Screenshot from PC (what it should look like on phone) - https://love2d.org/imgmirrur/h1XX5uP.png
Attached is also the game.love file created with the code (sorry if it's a mess)
Thank you again for anyone that can assist in me understanding this