I have a square which being placed inside a circle field produce a notification after touch ended phase.
Look at this:
local circle = display.newCircle(150,150,40) circle.alpha = 0.5 local square = display.newRect(50,50,20,20) local function moveSquare( event ) local t = event.target local phase = event.phase if "began" == phase then local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) t.isFocus = true elseif t.isFocus then if "moved" == phase then t.x = event.x t.y = event.y elseif "ended" == phase then local bounds = circle.contentBounds if square.x > bounds.xMin and square.x < bounds.xMax and square.y > bounds.yMin and square.y < bounds.yMax then print("Inside circle!") end end end return true end square:addEventListener ( "touch", moveSquare )
Ok, it works perfectly.
But, I need a circle to detect that an object has just entered the circle’s area.
Help me, please, to make inverse for the code.
Which event listener and event.name would you recommend in this case, because a static circle is not performed by touch or tap… only a square, only hardcore…
One more question is: how to detect some different objects, I mean a situation like a circle “detects” if a red square entered the circle’s area or a green triangle, etc.
As for me, it is better to describe one Class Prototype in code for every of 64 square of a chessboard as “a detector” than make every chess piece like a source of situational messages:
chessPiece:touch ( event )
( event.phase == “ended” )
print ( “Now I am at E4!” )
print ( "Now I am at G7! ")
Could it be resolved by any “object ID”?
Thanks for any ideas, sorry for newbee kuestions))