Game is in top-left corner? [Android-SDL2]

A project to port LÖVE to Android handhelds
Locked
TheWaffleDimension
Prole
Posts: 14
Joined: Wed Dec 02, 2015 11:14 pm

Game is in top-left corner? [Android-SDL2]

Post by TheWaffleDimension » Fri Dec 04, 2015 10:46 pm

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.

TheWaffleDimension
Prole
Posts: 14
Joined: Wed Dec 02, 2015 11:14 pm

Re: Game is in top-left corner? [Android-SDL2]

Post by TheWaffleDimension » Sat Dec 05, 2015 5:55 pm

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.

User avatar
master both
Party member
Posts: 227
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Game is in top-left corner? [Android-SDL2]

Post by master both » Sat Dec 05, 2015 7:08 pm

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 :)

TheWaffleDimension
Prole
Posts: 14
Joined: Wed Dec 02, 2015 11:14 pm

Re: Game is in top-left corner? [Android-SDL2]

Post by TheWaffleDimension » Sun Dec 06, 2015 9:45 pm

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! :P Would it be fine if I used your code for other projects, since it seems to work really well?

User avatar
master both
Party member
Posts: 227
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Game is in top-left corner? [Android-SDL2]

Post by master both » Mon Dec 07, 2015 1:45 am

TheWaffleDimension wrote: Would it be fine if I used your code for other projects, since it seems to work really well?
Sure, why not.

TheWaffleDimension
Prole
Posts: 14
Joined: Wed Dec 02, 2015 11:14 pm

Re: Game is in top-left corner? [Android-SDL2]

Post by TheWaffleDimension » Fri Dec 11, 2015 10:35 pm

master both wrote: Sure, why not.
Alright. Thanks! :awesome:

Locked

Who is online

Users browsing this forum: No registered users and 1 guest