You will need to store the swipe pattern and then compare that to the predefined “unlock” swipe pattern.
You can do this by storing a pattern that is x + (y*12) an doing a compare of the indices.
You will need to store the swipe pattern and then compare that to the predefined “unlock” swipe pattern.
You can do this by storing a pattern that is x + (y*12) an doing a compare of the indices.
I just want the line which extends as shown.
e.phase = “start” >>> Find the closest dot to the start touch
e.phase = “moved” >>> Find the closest dot to the current touch. If it is another dot than the start dot, draw a line between the start dot and the current dot (and remove the last line if you drew one)
e.phase = “ended” >>> Save the line that was created. If you want to make a polygon, the last dot will be your new start dot for the next touch event.
You can repeat that until you hit the first dot again. Then you can create a polygon out of the values.
I have successfully created a simple editor which creates objects by joining the Dots
But after adding the Body in Physics engines the Outlines(or Object) is getting outside as you can see.
[sharedmedia=core:attachments:7208]
why is body(Outlines) getting created at a different position when added in the physics engine?
I think default co-ordinate for the body in physics engine is 0,0
can we use anchor while adding body in the physics engine
local poly = display.newPolygon(dotCollect[1],dotCollect[2], dotCollect) poly:addEventListener("touch",dragObject) local offset\_x, offset\_y = offset\_xy(dotCollect) poly.x = offset\_x poly.y = offset\_y physics.addBody( poly,"static",{shape=dotCollect} )
dotCollect stores vertices of the polygon .
here is code to get the offset_xy of polygon
local function offset\_xy( t ) local table\_sort = table.sort local coordinatesX, coordinatesY = {}, {} local minX, maxX, minY, maxY local function compare( a, b ) return a \> b end for i = 1, #t\*0.5 do coordinatesY[i] = t[i\*2] end for i = 1, #t\*0.5 do coordinatesX[i] = t[i\*2-1] end table\_sort( coordinatesX, compare ) maxX = coordinatesX[1] minX = coordinatesX[#coordinatesX] table\_sort( coordinatesY, compare ) maxY = coordinatesY[1] minY = coordinatesY[#coordinatesY] local offset\_x = (minX+maxX)\*0.5 local offset\_y = (minY+maxY)\*0.5 return offset\_x, offset\_y end
thanks
I don’t think you can use ‘dotCollect’ as the shape of the body.
You need to change the offset of those points first.
i.e. Something like this:
local poly = display.newPolygon(dotCollect[1],dotCollect[2], dotCollect) poly:addEventListener("touch",dragObject) local offset\_x, offset\_y = offset\_xy(dotCollect) poly.x = offset\_x poly.y = offset\_y local shape = {} for i = 1, #dotCollect, 2 do shape[i] = dotCollect[i] - offset\_x shape[i+1] = dotCollect[i+1] - offset\_y end physics.addBody( poly,"static",{shape=shape} )
PS - The body shape needs to be relative to the object’s <0,0> point.
PPS - Body shape vertices are in object space, not world space. Whereas, the polygon vertices are in world space.
Thanks, man.it’s working now