如何在 lua、corona SDK 中使用 onComplete
How to use the onComplete in lua, corona SDK
我无法弄清楚我犯的错误是什么。如果你能帮助我,我会很高兴。我希望一个 transition.to() 发生在另一个之后。
local ball = display.newCircle(160,0,30)
local function move()
ball.x = display.contentWidth/2
ball.y = display.contentWidth-display.contentWidth-ball.contentWidth*2
transition.to(ball, {x=display.contentWidth/2, y=display.contentHeight*1.3, time=5000, onComplete=move2})
end
local function move2()
ball.x = display.contentWidth+ball.contentWidth/2
ball.y = 0-ball.contentWidth/2
transition.to(ball, {x=0-ball.contentWidth/2, y=display.contentHeight+ball.contentWidth/2, time = 5000})
--transition.to(ball,{x=160,y=240})
end
move()
你有什么问题?
尝试(已测试)
local ball = display.newCircle(160,0,30)
local function move2()
ball.x = display.contentWidth + ball.width * 0.5
ball.y = -ball.width * 0.5
transition.to(ball, {x=-ball.width * 0.5, y=display.contentHeight + ball.width * 0.5, time = 5000})
end
local function move()
ball.x = display.contentWidth * 0.5
ball.y = -ball.width * 2
transition.to(ball, {y=display.contentHeight * 1.3, time=5000, onComplete=move2})
end
move()
在使用函数名之前,您必须声明同名变量或将函数主体部分放在您第一次使用它的地方之上。
如果您想在 move2
中的 transition.to
完成后再次调用 move
函数,只需使用下面的代码
local ball = display.newCircle(160,0,30)
local move
local function move2()
ball.x = display.contentWidth + ball.width * 0.5
ball.y = -ball.width * 0.5
transition.to(ball, {x=-ball.width * 0.5, y=display.contentHeight + ball.width * 0.5, time = 5000, onComplete=move})
end
function move()
ball.x = display.contentWidth * 0.5
ball.y = -ball.width * 2
transition.to(ball, {y=display.contentHeight * 1.3, time=5000, onComplete=move2})
end
move()
请注意,您获得了无限过渡。在 Corona blog.
上阅读有关功能范围的更多信息
我无法弄清楚我犯的错误是什么。如果你能帮助我,我会很高兴。我希望一个 transition.to() 发生在另一个之后。
local ball = display.newCircle(160,0,30)
local function move()
ball.x = display.contentWidth/2
ball.y = display.contentWidth-display.contentWidth-ball.contentWidth*2
transition.to(ball, {x=display.contentWidth/2, y=display.contentHeight*1.3, time=5000, onComplete=move2})
end
local function move2()
ball.x = display.contentWidth+ball.contentWidth/2
ball.y = 0-ball.contentWidth/2
transition.to(ball, {x=0-ball.contentWidth/2, y=display.contentHeight+ball.contentWidth/2, time = 5000})
--transition.to(ball,{x=160,y=240})
end
move()
你有什么问题?
尝试(已测试)
local ball = display.newCircle(160,0,30)
local function move2()
ball.x = display.contentWidth + ball.width * 0.5
ball.y = -ball.width * 0.5
transition.to(ball, {x=-ball.width * 0.5, y=display.contentHeight + ball.width * 0.5, time = 5000})
end
local function move()
ball.x = display.contentWidth * 0.5
ball.y = -ball.width * 2
transition.to(ball, {y=display.contentHeight * 1.3, time=5000, onComplete=move2})
end
move()
在使用函数名之前,您必须声明同名变量或将函数主体部分放在您第一次使用它的地方之上。
如果您想在 move2
中的 transition.to
完成后再次调用 move
函数,只需使用下面的代码
local ball = display.newCircle(160,0,30)
local move
local function move2()
ball.x = display.contentWidth + ball.width * 0.5
ball.y = -ball.width * 0.5
transition.to(ball, {x=-ball.width * 0.5, y=display.contentHeight + ball.width * 0.5, time = 5000, onComplete=move})
end
function move()
ball.x = display.contentWidth * 0.5
ball.y = -ball.width * 2
transition.to(ball, {y=display.contentHeight * 1.3, time=5000, onComplete=move2})
end
move()
请注意,您获得了无限过渡。在 Corona blog.
上阅读有关功能范围的更多信息