在我的一个日冕应用中,我将过渡到具有特定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"
任何建议都值得赞赏......
答案 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"