Can somebody help me create a skeleton code that flags when you touch three circles which and then a dispatch function creates a square.
Thanks
Jake [import]uid: 51459 topic_id: 13788 reply_id: 313788[/import]
Can somebody help me create a skeleton code that flags when you touch three circles which and then a dispatch function creates a square.
Thanks
Jake [import]uid: 51459 topic_id: 13788 reply_id: 313788[/import]
something like this? its too overcomplicated, i think it can be done with much less code, but i didnt spent time on that
[lua]c1touched = false
c2touched = false
c3touched = false
local circle1 = display.newCircle(0,0,20)
circle1.x = 50
circle1.y = 50
local circle2 = display.newCircle(0,0,20)
circle2.x = 150
circle2.y = 50
local circle3 = display.newCircle(0,0,20)
circle3.x = 100
circle3.y = 100
function dispatchsquare()
if c1touched == true and c2touched == true and c3touched == true then
local square = display.newRect(150,300, 60,60)
end
end
function flagcircle(event)
if event.phase == “ended” then
c1touched = true
end
end
function flagcircle2(event)
if event.phase == “ended” then
c2touched = true
end
end
function flagcircle3(event)
if event.phase == “ended” then
c3touched = true
end
end
Runtime:addEventListener(“enterFrame”, dispatchsquare)
circle1:addEventListener(“touch”, flagcircle)
circle2:addEventListener(“touch”, flagcircle2)
circle3:addEventListener(“touch”, flagcircle3)[/lua] [import]uid: 16142 topic_id: 13788 reply_id: 50618[/import]
Wow that was quick… I was really just having trouble with the dispatcher bit… heres the circle part simplified…
[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
local BG = display.newImage(“background.png”)
local rc = display.newImage(“rc.png”)
rc.x = 275; rc.y = 196
local yc = display.newImage(“yc.png”)
yc.x = 75; yc.y = 256
local gc = display.newImage(“gc.png”)
gc.x = 175; gc.y = 206
local function touchGreen(_e)
if _e.phase == “began” then
print(“touched green”)
end
end
local function touchRed(_e)
if _e.phase == “began” then
print(“touched red”)
end
end
local function touchYellow(_e)
if _e.phase == “began” then
print(“touched yellow”)
end
end
rc:addEventListener(“touch”, touchRed)
yc:addEventListener(“touch”, touchYellow)
gc:addEventListener(“touch”, touchGreen)[/lua] [import]uid: 51459 topic_id: 13788 reply_id: 50621[/import]
THANKS darkconsoles
[import]uid: 51459 topic_id: 13788 reply_id: 50622[/import]
Ok So now how do I detect that I have touch the square after it has been created? [import]uid: 51459 topic_id: 13788 reply_id: 50626[/import]
write a function and in a function where square being created attach an eventListener to it
that simple [import]uid: 16142 topic_id: 13788 reply_id: 50638[/import]
Jake, you made two threads for this; please don’t do that again and read the forum rules.
Also, darkconsoles, your code was good but your Runtime listener is a big mistake - that code would create over a thousand squares a minute after all three circles had been touched 
Peach [import]uid: 52491 topic_id: 13788 reply_id: 50713[/import]