使用id:corona SDK调用transition.to

时间:2013-05-09 19:11:17

标签: android transition corona objectid

在我的一个日冕应用中,我将过渡到具有特定id的对象。我怎么能这样做?

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" 

任何建议都值得赞赏......

1 个答案:

答案 0 :(得分: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"