Touching different objects to create one essential object.

Can someone help me create a skeleton program that detects three hit areas on a touch function… After three areas are hit then a dispatcher function creates one other hit area.
Thanks

Jake [import]uid: 51459 topic_id: 13785 reply_id: 313785[/import]

good work darkconsoles…
I just simplified the code
[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 circle1.touched == true and circle2.touched == true and circle3.touched == true then
local square = display.newRect(150,300, 60,60)
end
end

function flagcircle(event)
if event.phase == “ended” then
event.target.touched = true
dispatchsquare()
end
end

circle1:addEventListener(“touch”, flagcircle)
circle2:addEventListener(“touch”, flagcircle)
circle3:addEventListener(“touch”, flagcircle)[/lua] [import]uid: 71210 topic_id: 13785 reply_id: 50681[/import]

Yes! Jake, this is a perfect example of what I told you about last night - see how clean it is?

Great code as usual, Renvis :slight_smile: [import]uid: 52491 topic_id: 13785 reply_id: 50712[/import]

Thank you so much renvis!!!

Very clean indeed!!!
AND THANK YOU PRINCESS PEACH!!! [import]uid: 51459 topic_id: 13785 reply_id: 50727[/import]

you are welcome jakescarano. thanks for your nice words peach… :slight_smile:
[import]uid: 71210 topic_id: 13785 reply_id: 50733[/import]

Hey renvis how can I add a print statement saying that I touched the square after it has been made?

If you can show me in your same code it will help :slight_smile: [import]uid: 51459 topic_id: 13785 reply_id: 50789[/import]

SCRATCH THAT LAST MESSAGE… I FIGURED OUT A WAY CHECK IT OUT [lua]c1touched = false
c2touched = false
c3touched = false

local background = display.newImage(“background.png”)

local circle1 = display.newImage(“yc.png”)
circle1.x = 50; circle1.y = 250

local circle2 = display.newImage(“gc.png”)
circle2.x = 150; circle2.y = 250

local circle3 = display.newImage(“rc.png”)
circle3.x = 100; circle3.y = 250

local planet = display.newImage(“planet.png”)
planet.x = 100; planet.y = 250
planet.alpha = 0

local square = display.newRect(150,300, 60,60)
square.alpha = 0

function dispatchSquare()
if circle1.touched == true and circle2.touched == true and circle3.touched == true then
square.alpha = 1
planet.alpha = 1
end

end

function flagCircle(_e)
if _e.phase == “ended” then
_e.target.touched = true
dispatchSquare()
end
end

function flagSquare(_e)
if _e.phase == “ended” then
print(“hit square”)
end
end

square:addEventListener(“touch”, flagSquare)
circle1:addEventListener(“touch”, flagCircle)
circle2:addEventListener(“touch”, flagCircle)
circle3:addEventListener(“touch”, flagCircle)[/lua]
Can you just help me track which circle I am touching and removing the circle when touched :slight_smile: [import]uid: 51459 topic_id: 13785 reply_id: 50792[/import]

yea thats right…
if you wan’t to create the object only when the condition is met you may use the below code

[lua]local background = display.newImage(“background.png”)

local circle1 = display.newImage(“yc.png”)
circle1.x = 50; circle1.y = 250

local circle2 = display.newImage(“gc.png”)
circle2.x = 150; circle2.y = 250

local circle3 = display.newImage(“rc.png”)
circle3.x = 100; circle3.y = 250

function flagSquare(_e)
if _e.phase == “ended” then
print(“hit square”)
end
end

function dispatchSquare()
if circle1.touched == true and circle2.touched == true and circle3.touched == true then
local square = display.newRect(150,300, 60,60)
local planet = display.newImage(“planet.png”)
planet.x = 100; planet.y = 250
square:addEventListener(“touch”, flagSquare)
end

end

function flagCircle(_e)
if _e.phase == “ended” then
_e.target.touched = true
dispatchSquare()
end
end

circle1:addEventListener(“touch”, flagCircle)
circle2:addEventListener(“touch”, flagCircle)
circle3:addEventListener(“touch”, flagCircle)[/lua] [import]uid: 71210 topic_id: 13785 reply_id: 50802[/import]

Thanks thats what I originally wanted to accomplish but didn’t know how THANKS…

do you know how to make the circles appear with a delay… Not show up all at the same time… [import]uid: 51459 topic_id: 13785 reply_id: 50803[/import]

you may use the following code
[lua]local background = display.newImage(“background.png”)
local circle1,circle2,circle3
function flagSquare(_e)
if _e.phase == “ended” then
print(“hit square”)
end
end

function dispatchSquare()
if circle1.touched == true and circle2.touched == true and circle3.touched == true then
local square = display.newRect(150,300, 60,60)
local planet = display.newImage(“planet.png”)
planet.x = 100; planet.y = 250
square:addEventListener(“touch”, flagSquare)
end

end

function flagCircle(_e)
if _e.phase == “ended” then
_e.target.touched = true
dispatchSquare()
end
end

local function createYC()
circle1 = display.newImage(“yc.png”)
circle1.x = 50; circle1.y = 250
circle1:addEventListener(“touch”, flagCircle)
end

local function createGC()
circle2 = display.newImage(“gc.png”)
circle2.x = 150; circle2.y = 250
circle2:addEventListener(“touch”, flagCircle)
end

local function createRC()
circle3 = display.newImage(“rc.png”)
circle3.x = 100; circle3.y = 250
circle3:addEventListener(“touch”, flagCircle)
end

timer.performWithDelay(1500, createYC ,1)
timer.performWithDelay(2500, createGC ,1)
timer.performWithDelay(3500, createRC ,1)[/lua]
[import]uid: 71210 topic_id: 13785 reply_id: 50807[/import]

thank you so much envis@technowand!!!

Tech wond is right… The wand from cinderella you gave me exactly what I wished for thank you so much!!! This gives me a great start for my game!!
Thanks

Jake [import]uid: 51459 topic_id: 13785 reply_id: 50814[/import]

good to know that it worked… :slight_smile: [import]uid: 71210 topic_id: 13785 reply_id: 50815[/import]

Glad all looks well here, no worries on the kind words Renvis; you makes HEAPS of great posts :slight_smile: (I often go into a thread ready to answer and there you are!)

No worries Jake - glad you seem to have it all sorted now :slight_smile:

Peach [import]uid: 52491 topic_id: 13785 reply_id: 50873[/import]

@peach that happens to me also. I usually replies to posts which are left unanswered. :slight_smile:
next time onward may be we should flag a post saying “am thinking about this”. LOL .If you are replying a post then there is no need that I spend time on it as you will be posting the perfect solution. :slight_smile:

[import]uid: 71210 topic_id: 13785 reply_id: 50884[/import]

Haha, thanks - I don’t know that all of my solutions are prefect but I try :wink:

Yours are great too - and it’s awesome you try to post on answered ones. Unfortunately I (and other staff who post here) can’t be around 24/7 so it’s nice to pop back on in the morning and see people have still gotten quick help :slight_smile:

Peach [import]uid: 52491 topic_id: 13785 reply_id: 51094[/import]

Technowand is a bamf. [import]uid: 61600 topic_id: 13785 reply_id: 51134[/import]

What is a bamf? [import]uid: 51459 topic_id: 13785 reply_id: 51137[/import]

Couple of observations…

[lua]function dispatchSquare()
if circle1.touched == true and circle2.touched == true and circle3.touched == true then
local square = display.newRect(150,300, 60,60)
local planet = display.newImage(“planet.png”)
planet.x = 100; planet.y = 250
square:addEventListener(“touch”, flagSquare)
end

end[/lua]

The square object is scoped to only live within the “if” inside dispatchSquare(). If you want to access that object later, it won’t be accessible (if Lua scopes like every other language).

Instead try this:

[lua]local square
local planet

function dispatchSquare()
if circle1.touched == true and circle2.touched == true and circle3.touched == true then
square = display.newRect(150,300, 60,60)
planet = display.newImage(“planet.png”)
planet.x = 100; planet.y = 250
square:addEventListener(“touch”, flagSquare)
end

end[/lua]

Now planet and square live outside of that function.

The second observation instead of setting .alpha to 0, you could use .isVisible = false / .isVisible = true

instead. There could be a behavior change though with the touch handlers though. [import]uid: 19626 topic_id: 13785 reply_id: 51144[/import]

@robmiracle thanks for the comments :slight_smile: [import]uid: 71210 topic_id: 13785 reply_id: 51244[/import]

Thanks robmiracle… Does any body know how to remove each circle upon each touch and have them reappear in a different location so that it is a continues loop? [import]uid: 51459 topic_id: 13785 reply_id: 51354[/import]