Help with android touchpad using touchscreen
Posted: Fri Feb 17, 2017 12:24 am
Hello there lovely freinds, Boy do I have some ugly code for you today! So im in a car driving through chicago with my aunt, and i decided to take a stab at writing a touch operated directional pad to move my player in my game... i am absolutely dumbfounded at the way i can implement this... Basically ive tried to assaign love.gettouches x and y values to a global variable and then check if that global variable is within the arrow pads and then move char... etc. But whenever i touch a directional pad and lift my finger, The control pad stays pressed! all I need it to do is stop moving when i lift my finger DX. Any help would be much appreciated.
Oh and heres the code.
Oh and heres the code.
Code: Select all
function ScreenTouches()
local touches = love.touchpressed( )
released = love.touchreleased( )
for i, id in ipairs(touches) do
tchx, tchy = love.touch.getPosition(id)
end
end
function Touchpad()
if tchx > rx and tchx < rx+rightarrow:getWidth() and tchy > ry and tchy < ry+rightarrow:getHeight() then
player.x = player.x + player.speed * delt
end
if tchx > lx and tchx < lx+leftarrow:getWidth() and tchy > ly and tchy < ly+leftarrow:getHeight() then
player.x = player.x - player.speed * delt
end
if tchx > dx and tchx < dx+downarrow:getWidth() and tchy > dy and tchy < dy+downarrow:getHeight() then
player.y = player.y + player.speed * delt
end
if tchx > ux and tchx < ux+uparrow:getWidth() and tchy > uy and tchy < uy+uparrow:getHeight() then
player.y = player.y - player.speed * delt
end
end