#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Button tween problem

edited August 2014 Posts: 20

I won't to make a button that when it is pushed a nother button fly's in.
I use this button class to draw the buttons but because the tween is in the button the second button is already drawn on his final place, so there is no more tween when i push the first button. Is there a way for this to work.

``````Buttons = class()

function Buttons:init(btnOne,btnTwo,x,y)
self.pos={x=-100,y=500}
self.btnOne=btnOne
self.btnTwo=btnTwo
self.selected=false
self.action=nil

--   rect(self.pos.x,self.pos.y,100,100)
self.w,self.h=50,50 -- spriteSize("Cargo Bot:Condition Green")
tween(5,self.pos,{x=x,y=y},{easing= tween.easing.cubicIn  ,loop= tween.loop.once})
end

function Buttons:draw()
stroke(255, 224, 0, 255)
fill(c)
ellipse(self.pos.x,self.pos.y,100)
if self.selected == true  then
rect(self.btnTwo, self.pos.x,self.pos.y,self.w+90,self.h)
elseif self.selected == false then
rect(self.btnOne,self.pos.x,self.pos.y,self.w+90,self.h)
end
end

function Buttons:touched(touch)
if touch.state == BEGAN or touch.state == MOVING  then
if math.abs(self.pos.x - touch.x) <= (self.w/2+90) and
math.abs(self.pos.y - touch.y) <= (self.h/2) then
self.selected = true
else
self.selected = false
end
elseif touch.state == ENDED then
if  self.selected == true and self.action then
self.action()
end
self.selected = false
end
end

``````
Tagged: