Moving groups "as one"

This was a test run that I may include later on.

It failed.

ball = display.newCircle(60,60,60,60)  
square = display.newRect(300,300,100,100)  
  
group = display.newGroup()  
  
group:insert(ball)  
group:insert(square)  
  
function moveball(event)  
print("touched")  
transition.to( ball, { time=1500, x=event.x, y=event.y} )  
  
end  
  
function check()  
if (ball.x \>= 300) then  
print("over 300")  
transition.to( group, { time=1500, x=ball.x-300} )  
end  
end  
Runtime:addEventListener("touch", moveball)  
Runtime:addEventListener("enterFrame", check)  

What is wrong with that?
(using “transition.to( ball, { time=1500, x=ball.x-300} )” would work so the code is fine) [import]uid: 79135 topic_id: 14325 reply_id: 314325[/import]

I think it may be because you are trying to move the ball and the group at the same time even though the ball is one of the items in the group. [import]uid: 31262 topic_id: 14325 reply_id: 52923[/import]

This isn’t perfect but you will at least see them moving. I pulled the runtime listeners once the ball was in place. Moving it around while trying to transition it and it’s group isn’t a good idea :wink:

[lua]
myGroup = display.newGroup()

ball = display.newCircle(60,60,60,60)
square = display.newRect(300,300,100,100)

myGroup:insert(ball)
myGroup:insert(square)

function moveball(event)
print(“touched”)
transition.to( ball, { time=1500, x=event.x, y=event.y} )
end

function check(event)
if (ball.x >= 300) then
Runtime:removeEventListener(“touch”, moveball)
Runtime:removeEventListener(“enterFrame”, check)
print “300”
transition.to(myGroup, {time =1000, x=-200})
end
end
Runtime:addEventListener(“touch”, moveball)
Runtime:addEventListener(“enterFrame”, check)[/lua]

Have a play with that :slight_smile:

Peach [import]uid: 52491 topic_id: 14325 reply_id: 53035[/import]