The title was too short to explain my problem fully, so here it is:
Right now, keyboard movement controls for my game are working perfectly ("a" to move left, "d" to move right, "space" to jump). However, I also want to test movement on my Android phone, and I'm not sure how Love2d touch functions work (as the wiki isn't very clear). For example, after I get a camera set up (currently in progress), my player should be centered in the middle of the screen. A touch and hold on the left side of the screen would make the player move to the right, and a touch and hold on the right should make the player move to the left, with doubletap to jump. As soon as touch is released, the player should stop moving. Any suggestions as to how I should set this up?
Love2d touch functions?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Love2d touch functions?
What parts of the wiki are unclear?
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.
- miniaturedog
- Prole
- Posts: 11
- Joined: Sat Apr 27, 2019 8:21 pm
Re: Love2d touch functions?
If you do not need handling simultaneous touches, you don't need to use touch; you can just use the mouse functions.
If you need to handle simultaneous touches, the only significant difference between the mouse functions and the touch functions is that each touch (each finger in contact with the screen) is assigned an id, which you're given.
You can track how many touches there are, and at which coordinates, by using the id as the key of a table.
Untested:
If you need to handle simultaneous touches, the only significant difference between the mouse functions and the touch functions is that each touch (each finger in contact with the screen) is assigned an id, which you're given.
You can track how many touches there are, and at which coordinates, by using the id as the key of a table.
Untested:
Code: Select all
local touches = {}
function love.touchpressed(id, x, y)
touches[id] = {x, y}
end
function love.touchmoved(id, x, y)
touches[id][1] = x
touches[id][2] = y
end
function love.touchreleased(id, x, y)
touches[id] = nil
end
local function howManyTouches()
return #touches
end
function isRectangleBeingTouched(rect)
for k, v in pairs(touches) do
if rect:containsPoint(v[1], v[2]) then
return true
end
end
return false
end
Re: Love2d touch functions?
Please am creating a game on android platform can i get the code for touch i.e touchPressed etc stuffs like dat and site where i can get it please
-
- Prole
- Posts: 8
- Joined: Sat Apr 06, 2024 12:30 am
Re: Love2d touch functions?
I am no Love2D expert, (in fact I just joined) but it might use the mouse and you just have to add an if clicked statement for a mobile version.miniaturedog wrote: ↑Tue Apr 30, 2019 2:27 pm The title was too short to explain my problem fully, so here it is:
Right now, keyboard movement controls for my game are working perfectly ("a" to move left, "d" to move right, "space" to jump). However, I also want to test movement on my Android phone, and I'm not sure how Love2d touch functions work (as the wiki isn't very clear). For example, after I get a camera set up (currently in progress), my player should be centered in the middle of the screen. A touch and hold on the left side of the screen would make the player move to the right, and a touch and hold on the right should make the player move to the left, with doubletap to jump. As soon as touch is released, the player should stop moving. Any suggestions as to how I should set this up?
Who is online
Users browsing this forum: No registered users and 13 guests