2013-05-09 3 views
1

내 코로나 애플리케이션 중 하나에서 특정 id 인 오브젝트로 전환을 적용해야합니다. 어떻게해야합니까? 어떤 조언을 감지 할 수있다id : corona SDK를 사용하여 transition.to를 호출하십시오.

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" 

... 당신은 테이블에있는 모든 개체를 저장할 수 있습니다

답변

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" 
관련 문제