hi,
- i would do this :
my character is behind a obstacle when i clic on this obstacle i receive for example:
character 1 touched
obstacle touched
But what i want receive is only :
obstacle touched
I love that my obstacle prevents one can with a click on my character. I have put my main.lua below :
--my main.lua : local backgroundInvisible=display.newRect(0,0,2000,2000) backgroundInvisible.alpha=0.01 backgroundInvisible.myId=200 local character={} for i=1,5 do character[i]=display.newCircle(100,100,20) character[i].myId=(i) character[i]:setFillColor(0,0,1)--blue end local obstacle={} for i=1,2 do obstacle[i]=display.newRect(100,100,200,200) obstacle[i].myId=40 obstacle[i]:setFillColor(0,1,0) end local bomb={} for i=1,2 do bomb[i]=display.newCircle(120,100,10) bomb[i].myId=50 bomb[i]:setFillColor(1,0,0) end local function touchCharacter(event) if event.phase =="ended" then target = event.target for k=1,200 do if target.myId == (k) then if k \<=5 then print("character",k,"touched") elseif k == 40 then print("obstacle touched") elseif k == 50 then print("boum!!!!") elseif k == 200 then print("background touched") end--for end--if end--if end--if end--touchCharacter for i=1,#character do character[i]:addEventListener("touch",touchCharacter) end for i=1,#obstacle do obstacle[i]:addEventListener("touch",touchCharacter) end for i=1,#bomb do bomb[i]:addEventListener("touch",touchCharacter) end backgroundInvisible: addEventListener("touch",touchCharacter)
- my second question is about my bomb
when i clic on a bomb and if a character is near of this bomb i would receive :
boum!!!
character 1 touched
except do this but it is resource hungry, have you a better solution ?
local cnttest=0 local function testPosition(k,bomb,character) print(bomb[k].x, bomb[k].y) for i=1,#character do print(character[i].x,character[i].y) if character[i].x==bomb[k].x+10 or character[i].x-10==bomb[k].x and character[i].y==bomb[k].y+10 or character[i].y-10==bomb[k].y then cnttest=cnttest +1 if cnttest == 1 then print("boum!!!", "character", i, "touched") end end end end
thank you 