When I click on the objects it need to be give one but it add two , why?
[lua]
[lua]
function kor1:touch(event)
if ( kor1.fill.r == 1 and kor1.fill.g == 0 and kor1.fill.b == 0 ) then
score = score + 1
pscore.text = "Score: " … score
else
composer.gotoScene( “gameover” )
end
end
kor1:addEventListener(“touch”,kor1)
[/lua]
[/lua]
that touch event fires twice… once for 'began phase 'once for ‘end phase’
insert between lines 2 & 3 this : if event.phase == “ended” then
insert between lines 8 & 9 this : end
best of luck on you app!
Hey, try this – I did modify the code a bit but it should work.
local function kor1(event) if event.phase == "began" then if kor1.fill.r == 1 and kor1.fill.g == 0 and kor1.fill.b == 0 then score = score + 1 pscore.text = "Score: " .. score elseif composer.gotoScene( "gameover" ) end end end kor1:addEventListener ("touch", kor1 )
Good Luck!
that touch event fires twice… once for 'began phase 'once for ‘end phase’
insert between lines 2 & 3 this : if event.phase == “ended” then
insert between lines 8 & 9 this : end
best of luck on you app!
Hey, try this – I did modify the code a bit but it should work.
local function kor1(event) if event.phase == "began" then if kor1.fill.r == 1 and kor1.fill.g == 0 and kor1.fill.b == 0 then score = score + 1 pscore.text = "Score: " .. score elseif composer.gotoScene( "gameover" ) end end end kor1:addEventListener ("touch", kor1 )
Good Luck!