How to check if touch press is in a triangle [SOLVED]

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
test
Prole
Posts: 28
Joined: Sun Apr 14, 2019 2:36 pm

How to check if touch press is in a triangle [SOLVED]

Post by test » Sun Apr 21, 2019 10:20 am

I use love.graphics.polygon to draw triangles. But how can I check if touch press is in a triangle?
Last edited by test on Tue May 07, 2019 7:17 pm, edited 1 time in total.

User avatar
zorg
Party member
Posts: 2620
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to check if touch press is in a triangle

Post by zorg » Sun Apr 21, 2019 12:42 pm

Simple. You need to detect a collision between a triangle shape and a point. Löve doesn't have a built-in function for that. The internet has tons of examples though, just search it and adapt the code to lua.
Me and my stuff :3True 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.

User avatar
ivan
Party member
Posts: 1450
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: How to check if touch press is in a triangle

Post by ivan » Mon Apr 22, 2019 6:25 am

Point in triangle is a relatively simple check:
https://2dengine.com/?p=intersections#P ... e_triangle
If you want the touch area to be larger (circle) then it's slightly more complicated:
https://2dengine.com/?p=intersections#C ... s_triangle

Post Reply

Who is online

Users browsing this forum: Exabot [Bot] and 8 guests