How to react on warning message and delete polygon?
WARNING: Polygon could not be generated. The polygon outline is invalid, possibly due to holes or self-intersection.
How to react on warning message and delete polygon?
WARNING: Polygon could not be generated. The polygon outline is invalid, possibly due to holes or self-intersection.
This is very important, please help.
You need to post some code. It is obvious that you’re trying to create an invalid polygon, but without your code we can’t see what you’re doing wrong.
Yes, I create the wrong polygon, and my question is how to remove not properly created polygon? A warning message appears, but on the warning i can not react in the code.
require "physics" physics.start() physics.setDrawMode("hybrid") local vertices = {-100,-100,100,-100,-110,-150,110,-150} local polygon = display.newPolygon( 200, 200, vertices ) physics.addBody( polygon, "static", {density=1, friction=0, bounce=0 } )
I would start with catching the error in a pcall and handling it from there. If the newPolygon throws an exception it should not return a polygon object, so there is nothing to remove. Handling the exception is what you want to be concerned with:
http://docs.coronalabs.com/daily/api/library/global/pcall.html
horacebury, pcall not help. Sees no error.
what i’m to do?
Try rendering the polygon as a line and see if it looks right. I think the coordinates of the third point are wrong.
Does the newPolygon return an object or nil? If nil then there is nothing to remove. I suspect it is that function call which fails, not the addBody call.
horacebury, this does not help, try yourself.
I was finally able to try it myself. I’ve been responding on my phone.
There is no value or event returned in code that I can find to indicate that the polygon is self-intersecting. This is a shame because it’s a very powerful function to have. There are, however, plenty of sites out there which provide code for detecting self-intersecting polygon definitions. Eg:
FYI, I have created a feature request for information on self-intersecting polygon data:
horacebury, thanks!
Get done differently. I used physics.rayCast () to check the intersection. At the time when you draw a new side of the landfill, the beam scans the intersection with other lines.
You can actually calculate line intersections quite easily yourself. I’ve written a routine in my mathlib library to do it:
http://developer.coronalabs.com/code/line-intersection
You’ll need this to run with it:
This is very important, please help.
You need to post some code. It is obvious that you’re trying to create an invalid polygon, but without your code we can’t see what you’re doing wrong.
Yes, I create the wrong polygon, and my question is how to remove not properly created polygon? A warning message appears, but on the warning i can not react in the code.
require "physics" physics.start() physics.setDrawMode("hybrid") local vertices = {-100,-100,100,-100,-110,-150,110,-150} local polygon = display.newPolygon( 200, 200, vertices ) physics.addBody( polygon, "static", {density=1, friction=0, bounce=0 } )
I would start with catching the error in a pcall and handling it from there. If the newPolygon throws an exception it should not return a polygon object, so there is nothing to remove. Handling the exception is what you want to be concerned with:
http://docs.coronalabs.com/daily/api/library/global/pcall.html
horacebury, pcall not help. Sees no error.
what i’m to do?