tap listeners for different sprite phases

Hello everybody! I’m a new corona user and also new to code as well. I’ve been trying to work on a personal project that is supposed to be a tap music game.

Right now, I’m having trouble with figuring out how to have a tap event listener trigger on a different phase of the sprite. The idea is that the sprite will animate and play 5 frames, and depending on which frame the sprite is tapped on, it will give a different score.

I’ve browsed through the forums as well as googled, although I haven’t come up with a way to do this yet. I may simply just be looking for the wrong thing though. Here is my code that I set up for tapping and score and the actual object itself.

local function randomTap( event ) local function scoreUp( event ) score = score + 100 display.remove( timedTap ) timedTap = event.target if ( event.phase == "began" ) then score = score - 100 elseif ( event.phase == "next" ) then score = score - 60 elseif ( event.phase == "next" ) then score = score - 40 elseif ( event.phase == "next" ) then score = score - 20 elseif ( event.phase == "ended" ) then score = score + 0 end scoreText.text = "Score: " .. score end gameLoopTimer = timer.performWithDelay( 1000, display.remove( timedTap ), 1 ) timedTap = display.newSprite( sheetTap, sequencesTap ) timedTap.x = math.random( 25, 200 ) timedTap.y = math.random( 25, 400 ) timedTap:play() timedTap:addEventListener( "tap", scoreUp ) end

Hi @skinnyporkbun,

Welcome to Corona! When working with sprites, in your case, it’s most important that you focus on which “frame” the sprite is in, not really the “phase” of a sprite listener (which is different than a tap listener on the sprite). The following doc page shows you which properties of a sprite you can read at any time, and specifically “object.frame” is what you’d want to use to detect which current frame is being shown when the user taps on the sprite.

https://docs.coronalabs.com/api/type/SpriteObject/index.html

Hope this helps,

Brent

Thank you Brent. I applied what you’ve shown here and it works perfectly! I really appreciate the help.

Hi @skinnyporkbun,

Welcome to Corona! When working with sprites, in your case, it’s most important that you focus on which “frame” the sprite is in, not really the “phase” of a sprite listener (which is different than a tap listener on the sprite). The following doc page shows you which properties of a sprite you can read at any time, and specifically “object.frame” is what you’d want to use to detect which current frame is being shown when the user taps on the sprite.

https://docs.coronalabs.com/api/type/SpriteObject/index.html

Hope this helps,

Brent

Thank you Brent. I applied what you’ve shown here and it works perfectly! I really appreciate the help.