delay in enterframe event

Hi Guys,

My small code part is below.

I want to move the second rectangle_ which is called as a[2] _after 1 second later but both are moving simultaneously.

How can I do that?

Thanks in advance.

[lua]

local a = {}

a[1] = display.newRect(100,200, 20,20)

a[2] = display.newRect(100,100, 20,20)

local function move()

     for i = 1, 2 , 1 do

          if i == 2 then

               timer.performWithDelay( 2000, a[i]:translate( 1, 0 ) )

          else

               timer.performWithDelay( 0, a[i]:translate( 1, 0 ) )

          end

     end

end

Runtime:addEventListener( “enterFrame”, move )

[/lua]

  1. This is a timer, not enterFrame

  2. You’re not using timer.performWithDelay correctly.

You need closures (see my change to your calls below)

... timer.performWithDelay( 2000, function() a[i]:translate( 1, 0 ) end ) ... timer.performWithDelay( 0, function() a[i]:translate( 1, 0 ) end )

 Thank you so much roaminggamer

  1. This is a timer, not enterFrame

  2. You’re not using timer.performWithDelay correctly.

You need closures (see my change to your calls below)

... timer.performWithDelay( 2000, function() a[i]:translate( 1, 0 ) end ) ... timer.performWithDelay( 0, function() a[i]:translate( 1, 0 ) end )

 Thank you so much roaminggamer