Game is in top-left corner? [Android-SDL2]
-
- Prole
- Posts: 14
- Joined: Wed Dec 02, 2015 11:14 pm
Game is in top-left corner? [Android-SDL2]
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.
-
- Prole
- Posts: 14
- Joined: Wed Dec 02, 2015 11:14 pm
Re: Game is in top-left corner? [Android-SDL2]
I poked around the forums the bit, and found one about resolutions, and found this:
EDIT: I mean clicking on images that have been scaled.
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.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
EDIT: I mean clicking on images that have been scaled.
- master both
- Party member
- Posts: 262
- Joined: Tue Nov 08, 2011 12:39 am
- Location: Chile
Re: Game is in top-left corner? [Android-SDL2]
Hey you found my codeTheWaffleDimension 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.
![Smile :)](./images/smilies/ms-smile.png)
This is how I deal with mouse coordinated:
Code: Select all
local x,y = love.mouse.getPosition()
x = x/scalex
y = y/scaley
Code: Select all
_getPos = love.mouse.getPosition
function love.mouse.getPosition()
local x,y = _getPos()
return x/scalex, y/scaley
end
Good luck with your project
![Smile :)](./images/smilies/ms-smile.png)
-
- Prole
- Posts: 14
- Joined: Wed Dec 02, 2015 11:14 pm
Re: Game is in top-left corner? [Android-SDL2]
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!master both wrote:Hey you found my codeTheWaffleDimension 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.
This is how I deal with mouse coordinated:but you can also overwrite the functions like this for convinience:Code: Select all
local x,y = love.mouse.getPosition() x = x/scalex y = y/scaley
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.Code: Select all
_getPos = love.mouse.getPosition function love.mouse.getPosition() local x,y = _getPos() return x/scalex, y/scaley end
Good luck with your project
![Razz :P](./images/smilies/ms-razz.png)
- master both
- Party member
- Posts: 262
- Joined: Tue Nov 08, 2011 12:39 am
- Location: Chile
Re: Game is in top-left corner? [Android-SDL2]
Sure, why not.TheWaffleDimension wrote: Would it be fine if I used your code for other projects, since it seems to work really well?
-
- Prole
- Posts: 14
- Joined: Wed Dec 02, 2015 11:14 pm
Re: Game is in top-left corner? [Android-SDL2]
Alright. Thanks!master both wrote: Sure, why not.
![I'M SO HAPPY I COULD SHIT A RAINBOW RIGHT NOW :awesome:](./images/smilies/ms-awesome.png)
Who is online
Users browsing this forum: No registered users and 25 guests