Android: Push + lovepad overlay woes

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
LeviathaninWaves
Prole
Posts: 9
Joined: Sun Jul 17, 2022 12:46 am

Android: Push + lovepad overlay woes

Post by LeviathaninWaves »

I'm having a great deal of trouble getting these two libraries to play nice together. Essentially, since I'm using push to get pixelart friendly resolutions on a really high screen resolution and super wide aspect ratio device (Note 20 Ultra) I have issues getting lovepad (a library that implements a touchscreen gamepad overlay) to render correctly AND get logical touch coordinates that are 1:1 with the push display.

Solution 1) Draw lovepad in between push.start() and push.finish(), while adjusting lovepad's rendering and touch position code to accommodate the low resolution. This renders lovepad within push's rendering window and looks correct. However, the logical touchscreen x and y appear to be stretched across the entire display rather than within the push window. Here is the code in lovepad, I tried to modify this to work with the push resolution.

Code: Select all

	rxt, ryt = love.touch.getPosition(touch)
        local xt, yt = rxt / (love.graphics.getWidth() / render_w), ryt / (love.graphics.getHeight() / render_h)
           
        if (math.abs((xt - button.x))^2 + math.abs((yt - button.y))^2)^0.5 < button.radius then
        button.isDown = true
Where render_w and render_h is the target resolution w and h (400 x 240 in this case)

Solution 2) Render lovepad outside of push using love2D's native drawing functions. In the ideal world, it would work right out of the box as intended (and the gamepad wouldn't be confined to the lower width push resolution, but instead the entire device display) , but I can't figure out how to do this nor do I know if it's a sane approach.

It's worth noting that I'm also using the hump camera library, I don't know if this affects how this should be handled.
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: Android: Push + lovepad overlay woes

Post by GVovkiv »

LeviathaninWaves wrote: Fri Jul 22, 2022 7:54 pm I'm having a great deal of trouble getting these two libraries to play nice together. Essentially, since I'm using push to get pixelart friendly resolutions on a really high screen resolution and super wide aspect ratio device (Note 20 Ultra) I have issues getting lovepad (a library that implements a touchscreen gamepad overlay) to render correctly AND get logical touch coordinates that are 1:1 with the push display.

Solution 1) Draw lovepad in between push.start() and push.finish(), while adjusting lovepad's rendering and touch position code to accommodate the low resolution. This renders lovepad within push's rendering window and looks correct. However, the logical touchscreen x and y appear to be stretched across the entire display rather than within the push window. Here is the code in lovepad, I tried to modify this to work with the push resolution.

Code: Select all

	rxt, ryt = love.touch.getPosition(touch)
        local xt, yt = rxt / (love.graphics.getWidth() / render_w), ryt / (love.graphics.getHeight() / render_h)
           
        if (math.abs((xt - button.x))^2 + math.abs((yt - button.y))^2)^0.5 < button.radius then
        button.isDown = true
Where render_w and render_h is the target resolution w and h (400 x 240 in this case)

Solution 2) Render lovepad outside of push using love2D's native drawing functions. In the ideal world, it would work right out of the box as intended (and the gamepad wouldn't be confined to the lower width push resolution, but instead the entire device display) , but I can't figure out how to do this nor do I know if it's a sane approach.

It's worth noting that I'm also using the hump camera library, I don't know if this affects how this should be handled.
you probably need to adapt touch/click coordinates to push library.
i don't remember how push works, but it should have "to screen" and "to world" (or simillar functions).
For example, i have own scaling lib, https://github.com/Vovkiv/resolution_solution, it have toGame and toScreen functions, which allow you translate, for example, mouse/touch coordinates to scaled in-game coordinates.
Basically:

Code: Select all

return (x - rs.xOff) / rs.scaleWidth
Where X is coordinate of mouse/touch, xOff is width ob black bars and scaleWidth is scale value, that library produce to scale game to your desired resolution.
(same for Y, but instead use black bars height and width scale value).
Check example at bottom of my lib's file, i tried there explain this, maybe it will help.
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: Android: Push + lovepad overlay woes

Post by GVovkiv »

And as for camera libs...
They also might play not nicely with scaling. (at least, it's how was in case with my library).
I tried several (such as hump's solution, kikito's gamera, etc) and they always have something wrong with scaling.
The most easy to glue with my scaling solution and camera was https://github.com/Vovkiv/CameraMgr (which is fork of https://gitlab.com/V3X3D/love-libs/-/tr ... /CameraMgr), where i dirty added support for scaling.
(You need to pass into camera.update function dt, w, h, where w and h is desired resolution, which your game will be scaled to).

If scale library and camera library works nice, in most cases you will do, if you need to click on something that camera library shows:

Code: Select all

love.update = function(dt)
	local mouseX, mouseY = cameraLibrary.toWorld(scalingLibrary.toWorld(love.mouse.getPosition()))
	checkCollisionOfObjectOnCamera(mouseX, mouseY, width, height, ...)
end
And if need to, for example, click on ui:

Code: Select all

love.update = function(dt)
	local mouseX, mouseY = scalingLibrary.toWorld(love.mouse.getPosition())
	checkUIObject(mouseX, mouseY, width, height, ...)
end
Well, i hope it was useful for you...
LeviathaninWaves
Prole
Posts: 9
Joined: Sun Jul 17, 2022 12:46 am

Re: Android: Push + lovepad overlay woes

Post by LeviathaninWaves »

Thank you GVovkiv for sharing! You were right, push does have toGame(x, y)
The problem is, push documentation states that the function returns nil if coords from outside of the push display are given to it. This is not true, it returns false. Anyways with that function and some extra code, the lovepad works with push now. This is great for solution #1, but I'm still wondering how I can render the gamepad outside of push using the native screen resolution of my device.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot] and 5 guests