Scaling for android

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheHistoricApple
Prole
Posts: 26
Joined: Sun Jan 15, 2017 6:46 am

Scaling for android

Post by TheHistoricApple » Wed May 31, 2017 11:58 am

So i've been developing my game for android and i've tried multiple approaches to scaling but i can't figure it out.

my code so far is

Code: Select all

push:setupScreen(480, 320, width, height,{fullscreen = false}) --game resolution, window resolution, fullscreen

Code: Select all

function love.graphics.draw()
	push:apply("start")
	love.graphics.draw(background, 0, 0)
	love.graphics.draw(buttonui, 480 / 2 - (buttonui:getWidth() / 2), 320 / 2 - (buttonui:getHeight() / 2))
	love.graphics.setFont(font2)
	love.graphics.print("PLAY", 480 / 2 - (buttonui:getWidth() / 2) + 20,  320 / 2 - (buttonui:getHeight() / 2) + 15)
	love.graphics.setFont(font1)
	push:apply("end")
end
which on pc comes out to how i want
Untitled.png
Untitled.png (3.1 KiB) Viewed 3175 times
however once i compile it and run it on any of my two devices it comes out as
Screenshot_2017-05-31-07-56-11.png
Screenshot_2017-05-31-07-56-11.png (8.1 KiB) Viewed 3175 times
which is nowhere close to where i want.

i've even tried

Code: Select all

scale = love.window.getPixelScale()

function love.graphics.draw()
	love.graphics.push()
	love.graphics.scale(scale)
	love.graphics.draw(background, 0, 0)
	love.graphics.draw(buttonui, 480 / 2 - (buttonui:getWidth() / 2), 320 / 2 - (buttonui:getHeight() / 2))
	love.graphics.setFont(font2)
	love.graphics.print("PLAY", 480 / 2 - (buttonui:getWidth() / 2) + 20,  320 / 2 - (buttonui:getHeight() / 2) + 15)
	love.graphics.setFont(font1)
	love.graphics.pop()
end
which seemed like it had no affect at all.

any help would be greatly appreciated
heres the .love
game.love
(78.88 KiB) Downloaded 64 times

Lucyy
Prole
Posts: 42
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Re: Scaling for android

Post by Lucyy » Thu Jun 01, 2017 6:27 am

Instead of using hard coded variables to position your button in the middle, try replacing 480 and 320 with love.graphics.getDimensions

uederson
Prole
Posts: 28
Joined: Mon May 23, 2016 7:59 pm
Location: Brazil
Contact:

Re: Scaling for android

Post by uederson » Thu Jun 01, 2017 11:27 am

In my game I set default screen size on conf.lua file:

Code: Select all

function love.conf(t)
  t.window.width = 480
  t.window.height = 320
end
Get the screen size from the actual device where the game is running and the scale values:

Code: Select all

function love.load()
  local width, height = love.graphics.getDimensions()
  sx = width/480
  sy = altura/320
end
And I use love.graphics.scale() to scale the screen to the device's screen size:

Code: Select all

function love.draw()
  love.graphics.scale(sx,sy)
end
I don't know if this is the best way of do it, but I learned it here on the forum and it works!

User avatar
Positive07
Party member
Posts: 1005
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Scaling for android

Post by Positive07 » Thu Jun 01, 2017 11:38 am

Add this to the end of your main.lua

Code: Select all

love.resize = function (w, h)
   push:resize(w, h)
end
Long explanation: Push tries to set the screen mode to a fixed resolution which is most likely not supported by your device, so setMode fails and love.resize is called with the actual width and height of the screen, Push still believes that love.window.setMode succeeded so it uses the sizes you requested, which doesn't match those of the screen.

If this doesn't work you can also try adding the fullscreen flag to push:setupScreen

Code: Select all

push:setupScreen(480, 320, width, height,{fullscreen = true})
If you want to do this only on Android/iOS, you can do an if statement with love.system.getOS

If this STILL doesn't work, you should probably open an issue in the Push repository (since it's something Ulydev would most likely want to fix). I'm confident this won't be needed thoug
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

TheHistoricApple
Prole
Posts: 26
Joined: Sun Jan 15, 2017 6:46 am

Re: Scaling for android

Post by TheHistoricApple » Sat Jun 03, 2017 4:40 am

Lucyy wrote:
Thu Jun 01, 2017 6:27 am
Instead of using hard coded variables to position your button in the middle, try replacing 480 and 320 with love.graphics.getDimensions
Push does this for me, all I should have to do is get it "perfect" for one resolution.
Positive07 wrote:
Thu Jun 01, 2017 11:38 am
Add this to the end of your main.lua

Code: Select all

love.resize = function (w, h)
   push:resize(w, h)
end
Long explanation: Push tries to set the screen mode to a fixed resolution which is most likely not supported by your device, so setMode fails and love.resize is called with the actual width and height of the screen, Push still believes that love.window.setMode succeeded so it uses the sizes you requested, which doesn't match those of the screen.

If this doesn't work you can also try adding the fullscreen flag to push:setupScreen

Code: Select all

push:setupScreen(480, 320, width, height,{fullscreen = true})
If you want to do this only on Android/iOS, you can do an if statement with love.system.getOS

If this STILL doesn't work, you should probably open an issue in the Push repository (since it's something Ulydev would most likely want to fix). I'm confident this won't be needed thoug
Adding push:resize to the end fixed it. Thank you!

User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Scaling for android

Post by Dr. Peeps » Sun Feb 04, 2018 1:18 am

Unless I'm missing something, this is all dealing only with graphical output. I think the scaling issue is bigger than that. I've also been working on a game that I want to automatically scale to any device resolution (without having to rebuild). You will need to scale everything in the game to match: user touch/click positions, sprite collision boxes, UI button boxes, and so on. I'd suggest doing all coding using a normalized, "virtual" positioning system (with a set aspect ratio if need be), and then all of these virtual positions would be translated to the actual device positioning system on the fly.

I don't think there's any easy "plug & play" solution; you need to create a comprehensive scaling engine that will cover all parts of your game. If someone knows of a better way, I'm all ears! :monocle:

grump
Party member
Posts: 574
Joined: Sat Jul 22, 2017 7:43 pm

Re: Scaling for android

Post by grump » Sun Feb 04, 2018 2:19 am

Dr. Peeps wrote:
Sun Feb 04, 2018 1:18 am
I don't think there's any easy "plug & play" solution; you need to create a comprehensive scaling engine that will cover all parts of your game. If someone knows of a better way, I'm all ears! :monocle:
It all comes down to the fact that there's no way to query transformation states in 0.10.2. One workable approach I've learned from other löver's advice is to shadow the love.graphics functions, track the transformation state and roll your own matrices to compute transformed coordinates. Done correctly, this approach should work for all use cases, even for rotation and shearing.

Things are getting easier in that regard with 0.11 AFAIK.

DoctorEnder
Prole
Posts: 1
Joined: Thu Sep 27, 2018 10:07 am

Re: Scaling for android

Post by DoctorEnder » Thu Sep 27, 2018 10:26 am

To rescale your game you simply need to make a canvas, draw everything to that canvas instead of to the main window. Than just scale the canvas to the current window size.

Code: Select all

windowWidth, windowHeight = love.graphics.getDimensions()
canvasWidth, canvasHeight = 1280, 720 --or something like that


love.graphics.draw(canvas, 0, 0, windowWidth/canvasWidth, windowHeight/canvasHeight)
Once you do this you can decide on a concrete canvas width and height and draw based on those instead of trying to scale every variable in your game.

Astorek86
Prole
Posts: 16
Joined: Fri Jul 13, 2018 7:35 pm

Re: Scaling for android

Post by Astorek86 » Fri Sep 28, 2018 1:30 pm

There's also a Library called AspectRatio which provides useful Functions. It scales to every Output and has a function called "window_to_game_position" for, like, Touch- and/or Mouse-Controls. On my Project it's working perfectly^^.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests