Dragging a triangleShape

I inserted a triangle image and gave it dimensions. But when i drag the dimensions, i’m able to drag the image by clicking next to that image. Here is my code…
[lua]------------
–TRIANGLE–

local triangle = display.newImage(“triangle.png”)
triangle.x = 100
triangle.y = 100
triangleShape = { 5,-25, 57,50, -37,50 }
physics.addBody( triangle, “static”, { shape=triangleShape } )

– touch listener function

function triangle:touch( event )
if event.phase == “began” then

self.markX = self.x – store x location of object
self.markY = self.y – store y location of object

elseif event.phase == “moved” then

local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY

self.x, self.y = x, y – move object based on calculations above
end

return true
end

– make ‘myObject’ listen for touch events
triangle:addEventListener( “touch”, triangle )

[import]uid: 132369 topic_id: 33783 reply_id: 333783[/import]

Hello,
If the object is an image, its touch sensory area will be the rectangular bounds around it, even if you specify a triangular physics body for it (the body being independent of the sensory bounds). I believe you can set a mask for the object which would prevent touch outside its visual bounds, but that’s a separate step, not default.

Best regards,
Brent [import]uid: 200026 topic_id: 33783 reply_id: 134277[/import]

Thank you for replying. I’m a beginner for Lua, can you please give me link to a tutorial on how to do this? [import]uid: 132369 topic_id: 33783 reply_id: 134292[/import]

Hello again,
Happy to help… here’s a tutorial which steps you through the process. You basically need to mask the object (the triangle) and then use the isHitTestMasked property.

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/

Best of luck!
Brent [import]uid: 200026 topic_id: 33783 reply_id: 134301[/import]

Hi, i tried this tutorial on my project but after i applied the masks, my triangle is invisible and i can’t drag it. Thank you.
[lua]------------
–TRIANGLE–

local triangle = display.newImage(“triangle.png”)
triangle.x, triangle.y = display.contentCenterX, display.contentCenterY
triangleShape = { 5,-25, 57,50, -37,50 }
physics.addBody( triangle, “static”, { shape=triangleShape } )


local mask = graphics.newMask( “triangl1.png” )

– apply mask to object
triangle:setMask( mask )
triangle.maskScaleX = display.contentScaleX
triangle.maskScaleY = display.contentScaleY
triangle.maskX = triangle.contentWidth*0.5
triangle.maskY = triangle.contentHeight*0.5
triangle.isHitTestMasked = true
– [import]uid: 132369 topic_id: 33783 reply_id: 134327[/import]

make sure you follow all the mask image rules on the link Brent mentioned, if you dont your pay. :slight_smile: [import]uid: 118379 topic_id: 33783 reply_id: 134360[/import]

is your image setup correctly? [import]uid: 118379 topic_id: 33783 reply_id: 134359[/import]

Hello,
If the object is an image, its touch sensory area will be the rectangular bounds around it, even if you specify a triangular physics body for it (the body being independent of the sensory bounds). I believe you can set a mask for the object which would prevent touch outside its visual bounds, but that’s a separate step, not default.

Best regards,
Brent [import]uid: 200026 topic_id: 33783 reply_id: 134277[/import]

Thank you for replying. I’m a beginner for Lua, can you please give me link to a tutorial on how to do this? [import]uid: 132369 topic_id: 33783 reply_id: 134292[/import]

Hello again,
Happy to help… here’s a tutorial which steps you through the process. You basically need to mask the object (the triangle) and then use the isHitTestMasked property.

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/

Best of luck!
Brent [import]uid: 200026 topic_id: 33783 reply_id: 134301[/import]

Hi, i tried this tutorial on my project but after i applied the masks, my triangle is invisible and i can’t drag it. Thank you.
[lua]------------
–TRIANGLE–

local triangle = display.newImage(“triangle.png”)
triangle.x, triangle.y = display.contentCenterX, display.contentCenterY
triangleShape = { 5,-25, 57,50, -37,50 }
physics.addBody( triangle, “static”, { shape=triangleShape } )


local mask = graphics.newMask( “triangl1.png” )

– apply mask to object
triangle:setMask( mask )
triangle.maskScaleX = display.contentScaleX
triangle.maskScaleY = display.contentScaleY
triangle.maskX = triangle.contentWidth*0.5
triangle.maskY = triangle.contentHeight*0.5
triangle.isHitTestMasked = true
– [import]uid: 132369 topic_id: 33783 reply_id: 134327[/import]

make sure you follow all the mask image rules on the link Brent mentioned, if you dont your pay. :slight_smile: [import]uid: 118379 topic_id: 33783 reply_id: 134360[/import]

is your image setup correctly? [import]uid: 118379 topic_id: 33783 reply_id: 134359[/import]