Page 1 of 1
Game is in top-left corner? [Android-SDL2]
Posted: Fri Dec 04, 2015 10:46 pm
by TheWaffleDimension
I've created a game, and want to put it on Android, which I've made the apk. I'm encountering an issue when playing the game on Android, though. The game loads, and runs fine, but it's in the top left corner, and I can't find out how to stop that. While we're on the topic of screen resolution and such, how can I get my game to automatically get the size of the screen of the device, and fit itself automatically to it. I'm using the Android-SDL2.
Re: Game is in top-left corner? [Android-SDL2]
Posted: Sat Dec 05, 2015 5:55 pm
by TheWaffleDimension
I poked around the forums the bit, and found one about resolutions, and found this:
master both wrote:
This is the way I scale my games on any device.
Code: Select all
function love.load()
windowWidth = 480
windowHeight = 320
if love.system.getOS() == "Android" then
local x,y = love.window.getDimensions()
scalex = (x/windowWidth)
scaley = (y/windowHeight)
else
scalex = 1
scaley = scalex
end
love.window.setMode(windowWidth*scalex,windowHeight*scaley)
end
function love.draw()
love.graphics.scale(scalex,scaley)
-- draw everything here
end
That works well, and makes it so the game fits on the screen, but now I can't detect clicking on it properly. :/ Any help would be appreciated.
EDIT: I mean clicking on images that have been scaled.
Re: Game is in top-left corner? [Android-SDL2]
Posted: Sat Dec 05, 2015 7:08 pm
by master both
TheWaffleDimension wrote:
That works well, and makes it so the game fits on the screen, but now I can't detect clicking on it properly. :/ Any help would be appreciated.
EDIT: I mean clicking on images that have been scaled.
Hey you found my code
This is how I deal with mouse coordinated:
Code: Select all
local x,y = love.mouse.getPosition()
x = x/scalex
y = y/scaley
but you can also overwrite the functions like this for convinience:
Code: Select all
_getPos = love.mouse.getPosition
function love.mouse.getPosition()
local x,y = _getPos()
return x/scalex, y/scaley
end
Another thing you might wanted to do add is
love.window.getPixelScale somewhere on your code to deal with different pixel density phones, but I'm not sure how to make it work.
Good luck with your project
Re: Game is in top-left corner? [Android-SDL2]
Posted: Sun Dec 06, 2015 9:45 pm
by TheWaffleDimension
master both wrote:TheWaffleDimension wrote:
That works well, and makes it so the game fits on the screen, but now I can't detect clicking on it properly. :/ Any help would be appreciated.
EDIT: I mean clicking on images that have been scaled.
Hey you found my code
This is how I deal with mouse coordinated:
Code: Select all
local x,y = love.mouse.getPosition()
x = x/scalex
y = y/scaley
but you can also overwrite the functions like this for convinience:
Code: Select all
_getPos = love.mouse.getPosition
function love.mouse.getPosition()
local x,y = _getPos()
return x/scalex, y/scaley
end
Another thing you might wanted to do add is
love.window.getPixelScale somewhere on your code to deal with different pixel density phones, but I'm not sure how to make it work.
Good luck with your project
Yeah, and it's worked so far. I got it to work on my computer, so I've built it into an APK and it worked! Thanks for your help!
Would it be fine if I used your code for other projects, since it seems to work really well?
Re: Game is in top-left corner? [Android-SDL2]
Posted: Mon Dec 07, 2015 1:45 am
by master both
TheWaffleDimension wrote:
Would it be fine if I used your code for other projects, since it seems to work really well?
Sure, why not.
Re: Game is in top-left corner? [Android-SDL2]
Posted: Fri Dec 11, 2015 10:35 pm
by TheWaffleDimension
master both wrote:
Sure, why not.
Alright. Thanks!