[Resolved] Back and forth

Hello everyone! I want an image to continuously move back an forth between two coordinates. I tried to do it using some functions and transition:to, but I couldn’t get it to work. Does anyone know how to do this? Thanks!

Nathan [import]uid: 39302 topic_id: 26324 reply_id: 326324[/import]

Hey Nathan, run this;

[lua]local circle = display.newCircle( 50, 50, 20 )

local moveLeft

local function moveRight()
transition.to(circle, {x = 270, onComplete = moveLeft})
end

moveLeft = function()
transition.to(circle, {x=50, onComplete = moveRight})
end

moveRight()[/lua]

It’s just a simple demo showing a circle moving back and forth left and right, there’s no cancel function when you’re done with it and I haven’t specified the time parameter but I think it should give you a good base to go on.

Let me know if you have any questions!

Peach :slight_smile: [import]uid: 52491 topic_id: 26324 reply_id: 106706[/import]

Awesome! that’s exactly what I was looking for. :slight_smile: I was very close in my attempts… Thanks!

quick question… theres a button, then there’s an image covering the button. How do I prevent the button from being “pushable?” [import]uid: 39302 topic_id: 26324 reply_id: 106719[/import]

You’d use return true, like so;

[lua]local bg = display.newRect( 0, 0, 320, 480 )
local circle = display.newCircle( 160, 240, 60 )
circle:setFillColor(0,200,255)

local function touchBg()
print “BG touched”
end
bg:addEventListener(“tap”, touchBg)

local function touchCircle()
print “Circle touched”
return true
end
circle:addEventListener(“tap”, touchCircle)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 26324 reply_id: 106855[/import]

Thanks you. It wasn’t working, but I switched “tap” to "touch and it works. [import]uid: 39302 topic_id: 26324 reply_id: 106875[/import]