Could I have some help please.I've been stuck on this for hours. I'm trying to make an object move down then up when tapped.

Hey, I’m pretty new to corona I starting learning 2 days ago I’m really starting to get it. I’m just having one small issue. I have multiple characters a total of 4 and when you tap on them I want them to just straight down then right back up. I tried doing a transition but when I applied a transition to the other image it would not work. then I tried indexing the transitions but that also didn’t work the first image would do it right but the second one would not come back up after it went down 

Here’s the current code I have right now. I would appreciate all the help thank you!

local trans2

local ts = {2}

local index = 1

local Pepesad = display.newImageRect( “Pepesad.png”, 50, 50 )

Pepesad.x = 270

Pepesad.y = 450

 function Pepesad:tap ( event )

ts[Pepesad.tIndex] = transition.to(Pepesad, { time=2500, x=270, y=500, onComplete=trans2 })

end

trans2 = function ()

        ts[Pepesad.tIndex] = transition.to(Pepesad, { time=2500, x=270, y=450, onComplete=trans1 })

end

Pepesad.tIndex = index

Pepesad:tap( event )

index = index + 1

Pepesad:addEventListener( “tap”, Pepesad )


local Pepehappy = display.newImageRect( “Pepehappy.png”, 50, 50 )

Pepehappy.x = 50

Pepehappy.y = 450

function Pepehappy:tap ( event )

ts[Pepehappy.tIndex] = transition.to(Pepehappy, { time=2500, x=50, y=500, onComplete=trans2 })

end

trans2 = function ()

        ts[Pepehappy.tIndex] = transition.to(Pepehappy, { time=2500, x=50, y=450, onComplete=trans1 })

end

Pepehappy.tIndex = index

Pepehappy:tap( event )

index = index + 1

Pepehappy:addEventListener( “tap”, Pepehappy )


  1. Welcome to the community.

  2. Please format code posts in the future (I understand not doing so the first time you post; Just want you to know about this.  It helps us all)

formatyourcode.jpg

  1. I would change the code as follows ( may have typos ):

    local Pepesad = display.newImageRect( “Pepesad.png”, 50, 50 ) Pepesad.x = 270 Pepesad.y = 450 function Pepesad.trans1 = function( self ) self.onComplete = self.trans2 transition.to( self, { time=2500, x=270, y=500, onComplete = self } ) end function Pepesad.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=270, y=450, onComplete = self } ) end function Pepesad:tap( event ) transition.cancel( self ) self:trans1() end; Pepesad:addEventListener( “tap” ) -------------------------------------------------------- local Pepehappy = display.newImageRect( “Pepehappy.png”, 50, 50 ) Pepehappy.x = 50 Pepehappy.y = 450 function Pepehappy.trans1 = function( self ) self.onComplete = self.trans2 transition.to( self, { time=2500, x=50, y=500, onComplete = self } ) end function Pepehappy.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=50, y=450, onComplete = self } ) end function Pepehappy:tap( event ) transition.cancel( self ) self:trans1() end; Pepehappy:addEventListener( “tap” )

Thank you so much I really appreciate all the help! I’m glad to be a part of the community as well :slight_smile: I put that in and I’m getting an error where it ‘(’ expected near ‘=’ File: main.lua Line: 114) 

local Pepesad = display.newImageRect( "Pepesad.png", 50, 50 ) Pepesad.x = 270 Pepesad.y = 450 function Pepesad.trans1 = function( self ) -------(This is line 114 for me) self.onComplete = self.trans2 transition.to( self, { time=2500, x=270, y=500, onComplete = self } ) end function Pepesad.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=270, y=450, onComplete = self } ) end function Pepesad:tap( event ) transition.cancel( self ) self:trans1() end; Pepesad:addEventListener( "tap" ) 

Ah, my bad…

function Pepesad.trans1 = function( self ) -------(This is line 114 for me)

becomes

Pepesad.trans1 = function( self ) -------(This is line 114 for me)

One of those typos I warned might be in my post.

function Pepesad.trans1 = function( self )

this is line 114 I’m not too sure whats wrong with it :confused: thank you so much yeah I looked and it seems to be pretty dead on accruate.

Don’t respond to posts too fast (especially when I post)   :slight_smile:

I post, edit, re-edit, fix, tweak…   I’m weird that way.

If you look again you’ll see I edited my post.

My bad haha. Thank you so much for all the help! How do I get the object to stop right after they come up kind of like whack a mole where you tap them it goes down then comes back up and doesn’t go down until i tap it again, because right now when I tap them they keep going up and down. :/ 

function Pepesad.trans2 = function( self ) -- self.onComplete = self.trans1 self.onComplete = nil transition.to( self, { time=2500, x=270, y=450 } ) -- , onComplete = self } ) end

do the same for other pepe

That worked like a charm, you are the best! I just have one last thing, when I tap them multiple times the image starts to move really slow is there a way around that?

I don’t know the answer to that one off the top of my head.

Did you keep the transition.cancel() in the tap listener?

It’s all good and yeah i did 

  1. Welcome to the community.

  2. Please format code posts in the future (I understand not doing so the first time you post; Just want you to know about this.  It helps us all)

formatyourcode.jpg

  1. I would change the code as follows ( may have typos ):

    local Pepesad = display.newImageRect( “Pepesad.png”, 50, 50 ) Pepesad.x = 270 Pepesad.y = 450 function Pepesad.trans1 = function( self ) self.onComplete = self.trans2 transition.to( self, { time=2500, x=270, y=500, onComplete = self } ) end function Pepesad.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=270, y=450, onComplete = self } ) end function Pepesad:tap( event ) transition.cancel( self ) self:trans1() end; Pepesad:addEventListener( “tap” ) -------------------------------------------------------- local Pepehappy = display.newImageRect( “Pepehappy.png”, 50, 50 ) Pepehappy.x = 50 Pepehappy.y = 450 function Pepehappy.trans1 = function( self ) self.onComplete = self.trans2 transition.to( self, { time=2500, x=50, y=500, onComplete = self } ) end function Pepehappy.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=50, y=450, onComplete = self } ) end function Pepehappy:tap( event ) transition.cancel( self ) self:trans1() end; Pepehappy:addEventListener( “tap” )

Thank you so much I really appreciate all the help! I’m glad to be a part of the community as well :slight_smile: I put that in and I’m getting an error where it ‘(’ expected near ‘=’ File: main.lua Line: 114) 

local Pepesad = display.newImageRect( "Pepesad.png", 50, 50 ) Pepesad.x = 270 Pepesad.y = 450 function Pepesad.trans1 = function( self ) -------(This is line 114 for me) self.onComplete = self.trans2 transition.to( self, { time=2500, x=270, y=500, onComplete = self } ) end function Pepesad.trans2 = function( self ) self.onComplete = self.trans1 transition.to( self, { time=2500, x=270, y=450, onComplete = self } ) end function Pepesad:tap( event ) transition.cancel( self ) self:trans1() end; Pepesad:addEventListener( "tap" ) 

Ah, my bad…

function Pepesad.trans1 = function( self ) -------(This is line 114 for me)

becomes

Pepesad.trans1 = function( self ) -------(This is line 114 for me)

One of those typos I warned might be in my post.

function Pepesad.trans1 = function( self )

this is line 114 I’m not too sure whats wrong with it :confused: thank you so much yeah I looked and it seems to be pretty dead on accruate.

Don’t respond to posts too fast (especially when I post)   :slight_smile:

I post, edit, re-edit, fix, tweak…   I’m weird that way.

If you look again you’ll see I edited my post.

My bad haha. Thank you so much for all the help! How do I get the object to stop right after they come up kind of like whack a mole where you tap them it goes down then comes back up and doesn’t go down until i tap it again, because right now when I tap them they keep going up and down. :/ 

function Pepesad.trans2 = function( self ) -- self.onComplete = self.trans1 self.onComplete = nil transition.to( self, { time=2500, x=270, y=450 } ) -- , onComplete = self } ) end

do the same for other pepe

That worked like a charm, you are the best! I just have one last thing, when I tap them multiple times the image starts to move really slow is there a way around that?

I don’t know the answer to that one off the top of my head.

Did you keep the transition.cancel() in the tap listener?