Here you go, this is for a landscape, 480*320 setup, adjust the tri arrays for portrait etc. Enjoy!
[blockcode]
local north_tri_x = {0, 479, 239}
local north_tri_y = {0, 0, 159}
local south_tri_x = {239, 0, 479}
local south_tri_y = {160, 319, 319}
local west_tri_x = {0, 239, 0}
local west_tri_y = {0, 159, 320}
local east_tri_x = {479, 240, 479}
local east_tri_y = {0, 159, 479}
local function pointInPolygon(x, y, polyX, polyY)
local polySides=table.maxn(polyX)
local oddNodes=true
local counter=0
p1x = polyX[1]
p1y = polyY[1]
for i=1,polySides do
p2x=polyX[math.fmod(i,polySides)+1]
p2y=polyY[math.fmod(i,polySides)+1]
if y>math.min(p1y,p2y) then
if y<=math.max(p1y,p2y) then
if x<=math.max(p1x,p2x) then
if p1y~=p2y then
xinters=(y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
if p1x==p2x or x<=xinters then counter=counter+1 end
end
end
end
end
p1x = p2x
p1y = p2y
end
if math.fmod(counter,2)==0 then oddNodes=not oddNodes end
return oddNodes
end
function wtouch(event)
if(pointInPolygon(event.x,event.y,north_tri_x, north_tri_y) == true) then
myText.text = “North”
else
if(pointInPolygon(event.x,event.y,south_tri_x, south_tri_y) == true) then
myText.text = “South”
else
if(pointInPolygon(event.x,event.y,west_tri_x, west_tri_y) == true) then
myText.text = “West”
else
if(pointInPolygon(event.x,event.y,east_tri_x, east_tri_y) == true) then
myText.text = “East”
end
end
end
end
end
myText = display.newText( “”, 240, 50, native.systemFont, 18 )
myText:setTextColor( 244,0,0 )
myLine = display.newLine(0,0, display.contentWidth,display.contentHeight)
myLine:setColor(255,255,255)
myLine.width = 1
myLine = display.newLine(0, display.contentHeight, display.contentWidth, 0)
myLine:setColor(255,255,255)
myLine.width = 1
Runtime:addEventListener( “touch”, wtouch )
[/blockcode] [import]uid: 9371 topic_id: 4017 reply_id: 12262[/import]