Hi,
I'm planning on making a top down shooter game on android for android but I can't seem to get the buttons right.
I used GUI libraries like "SUIT" but it's doesn't support hold or I can't configure how. If you know how to make button (doesn't need to be complex just supports hold movement) please help me out. If you want to join me on my "On Android For Android" just tell me.
Thanks in advance.
Buttons on android?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Buttons on android?
I can't name library for android GUI, but this is code what I use:
(I tried to comment in English, my bad if you can't understand well.)
So if you want to separate between long press and short-tap, you should set threshold and check touch[id].time like:
Not sure if it will solve your problem, but I hope it helped.
(I tried to comment in English, my bad if you can't understand well.)
Code: Select all
-- love.touchpressed / love.touchmoved / love.touchreleased
-- Those are essential callback function for android touch event handling
-- But those callback functions won't call if you click mouse at PC, so you have to call it manually if you want to call it.
-- Code below will store touch inputs to touches{} table.
-- touches[id] = {x = x coords, y = y coords, time = how much time it got pressed}
-- You can add another informations if you want.
local touches = {}
function love.load()
count = 0
end
function love.draw()
local k, v
for k, v in pairs(touches) do
love.graphics.print(tostring(k) .. ":" .. math.floor(v.x) .. ":" .. math.floor(v.y) .. ":".. math.floor(v.time), v.x, v.y)
end
love.graphics.print(count, 0, 0)
end
function love.touchpressed(id, x, y)
touches[id] = {x = x, y = y, time = 0}
count = count + 1
end
function love.touchmoved(id, x, y)
if touches[id] ~= nil then
touches[id].x = x
touches[id].y = y
end
end
function love.touchreleased(id, x, y)
touches[id] = nil
count = count - 1
end
function love.update(dt)
-- store time to each touch gestures
local k, v
for k, v in pairs(touches) do
v.time = v.time + dt
end
end
----- callback function for mouse - for PC -----
function love.mousepressed(x, y, button, istouch)
if istouch == false then
love.touchpressed("mouse", x, y)
end
end
function love.mousemoved(x, y, dx, dy, istouch)
if istouch == false then
if love.mouse.isDown(1) then
love.touchmoved("mouse", x, y)
end
end
end
function love.mousereleased(x, y, button, istouch)
if istouch == false then
love.touchreleased("mouse", x, y)
end
end
--------------------------------------------------
Code: Select all
function love.touchreleased(id, x, y)
touches[id] = nil
count = count - 1
-- psudocode warning!
if button.clicked(button.x, button.y, button.width, button.height, x, y) == true then
if touches[id].time >= 1 then -- let's assume threshold is 1 sec
-- long-press
print("user long-pressed button")
else
-- short-tap
print("user short-tapped button")
end
end
end
Re: Buttons on android?
Hey, norubal,
Thank you for taking the time to reply and help me,
But as I am a beginner, I don't understand well.
If you have a discord account please join this server for future projects too.
We can work together and if you want you can join my project "From Android to Android".
Discord link: https://discord.gg/zmPNMTu4vg
Please join and let's help each other.
Thanks.
Thank you for taking the time to reply and help me,
But as I am a beginner, I don't understand well.
If you have a discord account please join this server for future projects too.
We can work together and if you want you can join my project "From Android to Android".
Discord link: https://discord.gg/zmPNMTu4vg
Please join and let's help each other.
Thanks.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Buttons on android?
or you can just join the löve discord instead...
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- Gunroar:Cannon()
- Party member
- Posts: 1120
- Joined: Thu Dec 10, 2020 1:57 am
Re: Buttons on android?
You could use gooi and gooi.newButton():onPress(),blah , blah, if I'm correct. Learn more: https://love2d.org/forums/viewtopic.php?t=79751
or you could use double joysticks because goois joystick isn't the best: https://love2d.org/forums/viewtopic.php?t=79732
or you could use double joysticks because goois joystick isn't the best: https://love2d.org/forums/viewtopic.php?t=79732
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests