2016-11-27 53 views
0

我很难弄清楚我犯的错误是什么。如果你能帮助我,我会很高兴。我想要一个transition.to()发生在另一个之后。如何在lua中使用onComplete,日冕软件开发工具包

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() 

回答

0

你的问题是什么?

尝试(测试)

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() 

在您使用功能名称必须声明具有相同名称的变量或函数放在与身体部位以上的地方,你第一次使用它。

如果你想再次调用move功能move2transition.to仅完成使用下面

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上的功能范围。

+0

@Idurniat如果我想要在函数move2()中完成transition.to之后去函数move()(该函数位于move()函数的上方),我应该怎么做?我希望我能够清晰关于我的问题。 – QuestionEverything

相关问题