Hi all!
How you making the multi touch support in your games?
So I want to move the map with touch of one finger or move and zoom with two fingers.
Move and zoom with multi touch
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1098
- Joined: Thu Dec 10, 2020 1:57 am
Re: Move and zoom with multi touch
Maybe this will help:
https://love2d.org/forums/viewtopic.php?t=84081
https://love2d.org/forums/viewtopic.php?t=84081
Re: Move and zoom with multi touch
Here is a zoom to mouse function i have lying around, i dont have time currently to write you a multi touch example, but this function would still be the base:
hope it helps.
Code: Select all
function love.keypressed(k)
if k=='escape' then
love.event.quit()
end
end
function love.load()
camera = {x=0, y=0, scale=1}
transform = love.math.newTransform(camera.x, camera.y, 0, camera.scale, camera.scale)
end
function love.draw()
love.graphics.applyTransform(transform)
love.graphics.print('hello world!', 300,300)
end
function getGlobalDelta(transform, dx, dy)
local dx1, dy1 = transform:transformPoint( 0, 0 )
local dx2, dy2 = transform:transformPoint( dx, dy )
local dx3 = dx2 - dx1
local dy3 = dy2 - dy1
return dx3, dy3
end
function love.wheelmoved(x,y)
-- grab the current mouse screen position
local posx, posy = love.mouse.getPosition()
-- figure out what world position that is
local invx, invy = transform:inverseTransformPoint(posx, posy)
-- do the actual zoom
if y >0 then
camera.scale = camera.scale*1.1
end
if y <0 then
camera.scale = camera.scale*.9
end
-- update the transform to be used in draw
transform = love.math.newTransform(camera.x, camera.y, 0, camera.scale, camera.scale)
-- with the new transform in place, find out what new world position the mouse points at now
local invx2, invy2 = transform:inverseTransformPoint(posx, posy)
-- figure out the difference between the old world position and the new
local dx = invx - invx2
local dy = invy - invy2
-- figure out how much that differnce is in the context of the camera itself
local dx2, dy2 = getGlobalDelta(transform, dx, dy)
-- update the camera with that offset
camera.x = camera.x - dx2
camera.y = camera.y - dy2
-- update the transform again, using the new offsets
transform = love.math.newTransform(camera.x, camera.y, 0, camera.scale, camera.scale)
end
Re: Move and zoom with multi touch
I have the zoom-to-mouse solution too, the movement with one finger too (actually it works native), but I have some problems by the two fingers move-and-zoom.
Re: Move and zoom with multi touch
Why the call
will be not respected?
Also the
returns wrong area.
Code: Select all
love.window.setMode(384, 805)
Also the
Code: Select all
self.x, self.y, self.w, self.h = love.window.getSafeArea()
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests