distinction between background and character's

hi,

i would have a distinction between the touch on my background and the touch on my character’s.

the behaviour of my snippet is that i have no distinction between the background and the Character’s. if i touch my character, the background also is touched.

how do you do for that ?

thanks for your’s advice.

function Backgroundinvisible:touch(event)     if event.phase == "ended" and clicback then --my action1 end end Backgroundinvisible:addEventListener( "touch", Backgroundinvisible ) local function characterTap(event) target = event.target for k=1,#Character do     if target.myId == (k) and clic then     --my action2     end   end end for i = 1, #Character do Character[i]:addEventListener("tap", characterTap) end

Hi @espace3d,

When handling touches, the touch will “propagate” (pass through) to other items behind unless you “return true” at the end of the touch handling function (of the object in front). Once you add that, the touch will stop at that object and not pass through to other objects.

[lua]

local function characterTap( event )

    --your code

    return true  --return true to prevent touch propagation

end

[/lua]

Brent

hi Brent,

thanks it works but i have an another worry. When i do multiple touch on my character i have not this behaviour in spite of my flag “clic”:

clic > functionOnCharacter() > level1 - clic > functionOnCharacter() > level2 - clic > functionOnCharacter() > level 3 - clic > functionOnCharacter() > level 4

but this behaviour : i have multiple instance of my functionOnCharacter

4x clic > functionOnCharacter() > level 4

               functionOnCharacter()

               functionOnCharacter()

               functionOnCharacter()

local function upgradeLevel() local function begin() local function wait() level = level + 1 print("level", level) clic = false end --wait timer.performWithDelay( 10000, wait) end --begin begin() end --upgradelevel

local function OnCharacter() upgradeLevel() end

local function tapOnCharacter(event) --clic true and false         target = event.target         for k=1,#Character do           if target.myId == (k) and clic then             clic = false          OnCharacter(k)         end --for     end --if return true end for i = 1, #Character do Character[i]:addEventListener("tap", tapOnCharacter) end

have you an idea to prevent that ? it’s difficult to describe so if you have an another question ask me. :slight_smile:

Hi @espace3d,

Do you mean that you have enabled multi-touch and receive multiple responses? This is logical and expected. If you want to prevent that, you’ll need to detect the ID of the first tap and then ignore any future taps on the character.

Brent

thanks Brent, i I had the multitouch activated and with multiple flag i have now only one tap.

Hi @espace3d,

When handling touches, the touch will “propagate” (pass through) to other items behind unless you “return true” at the end of the touch handling function (of the object in front). Once you add that, the touch will stop at that object and not pass through to other objects.

[lua]

local function characterTap( event )

    --your code

    return true  --return true to prevent touch propagation

end

[/lua]

Brent

hi Brent,

thanks it works but i have an another worry. When i do multiple touch on my character i have not this behaviour in spite of my flag “clic”:

clic > functionOnCharacter() > level1 - clic > functionOnCharacter() > level2 - clic > functionOnCharacter() > level 3 - clic > functionOnCharacter() > level 4

but this behaviour : i have multiple instance of my functionOnCharacter

4x clic > functionOnCharacter() > level 4

               functionOnCharacter()

               functionOnCharacter()

               functionOnCharacter()

local function upgradeLevel() local function begin() local function wait() level = level + 1 print("level", level) clic = false end --wait timer.performWithDelay( 10000, wait) end --begin begin() end --upgradelevel

local function OnCharacter() upgradeLevel() end

local function tapOnCharacter(event) --clic true and false         target = event.target         for k=1,#Character do           if target.myId == (k) and clic then             clic = false          OnCharacter(k)         end --for     end --if return true end for i = 1, #Character do Character[i]:addEventListener("tap", tapOnCharacter) end

have you an idea to prevent that ? it’s difficult to describe so if you have an another question ask me. :slight_smile:

Hi @espace3d,

Do you mean that you have enabled multi-touch and receive multiple responses? This is logical and expected. If you want to prevent that, you’ll need to detect the ID of the first tap and then ignore any future taps on the character.

Brent

thanks Brent, i I had the multitouch activated and with multiple flag i have now only one tap.