[Resolved] Drawing line within letter shape

Hi,
I am stuck at a point when user is drawing line within letter shape.(ex: A) I want to check condition and don’t allow to user to draw line outside of shape A. And I also want to check that user has completely drawn or not. Is it possible? If anyone have any idea let me know asap.
Any help will be appreciated.

Thanks.
Sabir [import]uid: 75428 topic_id: 27957 reply_id: 327957[/import]

This is really, really rough but you could use something like this with multiple shapes that should work;

[lua]local obj1 = display.newRect( 100, 100, 20, 100 )
obj1.rotation = 45

local dot = {}

local function test (event)
t = event.target
bounds = t.contentBounds
if event.x > bounds.xMin and event.x < bounds.xMax and event.y > bounds.yMin and event.y < bounds.yMax then
dot[#dot+1] = display.newCircle(event.x, event.y, 10)
dot[#dot]:setFillColor(255,0,0)
end
end
obj1:addEventListener(“touch”, test)[/lua]

Let me know how that goes for you :slight_smile:

Peach [import]uid: 52491 topic_id: 27957 reply_id: 113164[/import]

Thanks for reply Peach
But this is not my case because I’m working on Arabic letter and that is having different shapes.
I want user to draw line under the shape border only.
I am going to use another way and need your help.
can we detect event when I’m moving a object over other object? If this is possible then
i can do my job.
Thanks. [import]uid: 75428 topic_id: 27957 reply_id: 113167[/import]

Q: Can you detect when moving an object over another object?
A: Yes. There are multiple ways of doing this. You could have a touch listener on the object that is “underneath” and a flag, or you could use conentBounds and a flag.

Peach :slight_smile: [import]uid: 52491 topic_id: 27957 reply_id: 113194[/import]

Hi Peach,
I have already assign touch listener on the object that is “underneath”. but when object is moving over
underneath object then event is not detecting. I heve not idea conentBounds.
For more information I showing my code below.
[lua] onColission=function(event)
print(event.target.name)
eraseLine()
initializeCirclePos()
end

newLine = function ( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if “began” == phase then
stage:setFocus( body, event.id )
body.isFocus = true
---------writing line----------------
if(tempLine==nil) then
isLine = true
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine:setColor(rcolor, gcolor, bcolor)
tempLine.width=selectedWidth
prevX = event.x
prevY = event.y
end


elseif body.isFocus then
if “moved” == phase then

if body.x > display.contentWidth then
body.x = display.contentWidth - body.width
body.y = display.contentHeight - body.height
elseif body.x < 0 then
body.x = body.width
body.y=body.height
else
body.x = event.x
body.y=event.y
end

---------tracing line-------------------------

if(tempLine==nil) then
isLine = true
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine:setColor(rcolor, gcolor, bcolor)
------tempLine.width=30
tempLine.width=selectedWidth
prevX = event.x
prevY = event.y
end

if isLine == true then
ractgangle_hit[lineIndex] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[lineIndex]:setColor(rcolor, gcolor, bcolor)
-------ractgangle_hit[lineIndex].width = 30
ractgangle_hit[lineIndex].width = selectedWidth
local i
rc[rcIndex] = display.newCircle(ractgangle_hit[lineIndex].x,ractgangle_hit[lineIndex].y,selectedWidth/2)
rc[rcIndex]:setFillColor(rcolor, gcolor, bcolor);
writeScreen:insert(rc[rcIndex])
rcIndex = rcIndex + 1
ractgangle_hit[lineIndex].objname = “Point”…lineIndex
writeScreen:insert(ractgangle_hit[lineIndex])
–print("No of lines "…lineIndex)
prevX = event.x
prevY = event.y
lineIndex = lineIndex + 1
currLineIndex = currLineIndex + 1
end

circle:toFront()


------removeing draw line when its goes outside of line–
for i=1,#tracecontent[1].dot do
if event.target.x==tracecontent[imageIndex].dotpos[i].x and event.target.y==tracecontent[imageIndex].dotpos[i].y then
print(“STOP DRAWING”)
eraseLine()
initializeCirclePos()
break;
end
end
-------------end----------------------------------

elseif “ended” == phase or “cancelled” == phase then
stage:setFocus( body, nil )
body.isFocus = false
----------tracing line----------------------------

circle:toFront()


end
end

– Stop further propagation of touch event
return true
end

loadTraceLetter = function()
alphabetImage = content[1].image[imageIndex]…“trace.png”
soundIndex=content[1].image[imageIndex]
alphabet = display.newImageRect( alphabetImage, 522, 332)
alphabet.x = centerX
alphabet.y = centerY-30
storeScreenObjs(alphabet)
writeScreen:insert(alphabet)
---------------------loading dot image---------------

for p=1,#tracecontent[imageIndex].dot do
dotImg=display.newImageRect(tracecontent[imageIndex].dot[p]…".png",20,20)
dotImg.name=p
dotImg.x=tracecontent[imageIndex].dotpos[p].x
dotImg.y=tracecontent[imageIndex].dotpos[p].y
storeScreenObjs(dotImg)
writeScreen:insert(dotImg)
dotImg:addEventListener(“touch”, onColission)
end

--------display circle here----------------------
circle = display.newImageRect(“sabir.png”,90,90)
circle.xScale=0.5
circle.yScale=0.5
circle.x=tracecontent[imageIndex].cirPos[1].x
circle.y=tracecontent[imageIndex].cirPos[1].y
storeScreenObjs(circle)
circle:addEventListener( “touch”, newLine )
writeScreen:insert(circle)
return true

end

loadTraceLetter() [/lua] [import]uid: 75428 topic_id: 27957 reply_id: 113197[/import]

I believe setting the focus may be part of the issue, although I can’t read through this thoroughly tonight (time constraints) - if you post plug and play that would be helpful. [import]uid: 52491 topic_id: 27957 reply_id: 113309[/import]

Thanks Peach,
I got it.
The issue was with focus. [import]uid: 75428 topic_id: 27957 reply_id: 113327[/import]

Glad to hear it, good luck with your project!

Peach :slight_smile: [import]uid: 52491 topic_id: 27957 reply_id: 113452[/import]