1

In one of my corona apps, I've to apply transition to objects with certain id. How can I do this?

local ball = display.newImage("ball.png") 
   -- sample, actually there are random no. of balls created at an instant.
ball.id = "ball_id"

transition.to(ball,{time=200,x=400})
   -- here, instead of ball, i need to call all objects(if any) with id="ball_id" 

Any advice is appreciable...

4

1 回答 1

3

您可以将所有对象存储在一个表中。
即使您从台上移除一些物体,此解决方案也将起作用。
它有效,因为我使用了 ipairs。
更多信息: http: //lua-users.org/wiki/TablesTutorial

local balls = {}

local function createRandonBall( id )
    local ball = display.newImage("ball.png") 
    ball.id = id

    balls[#balls + 1] = ball
end

local function animateBall(id)

    for i, object in ipairs(balls) do
        if(object.id == id) then
            transition.to(object, {time=200,x=400} )
        end
    end

end


animateBall("ball_id")  //call all objects(if any) with id="ball_id"
于 2013-05-09T20:54:07.053 回答