2014-06-13 12 views
0

在我的堆棧上工作時,在編輯模式下,我可以通過箭頭鍵輕推任何控件。如何通過給定數量的像素將LiveCode中的對象移動?

我已經取得了一些成功,當我的籌碼與「移動」命令運行的移動控制e.g

move button 1 to 100,100 

是否有在運行時移動控件的任何更有效的方法?

+0

有一個十億方式更有效地做到這一點。你試圖解決的實際問題是什麼? – Mark

回答

2

根據您想要動畫的順利程度,您可以使用多種方法。在最簡單的層次上,您需要通過設置腳本中的位置相關屬性來移動腳本中的對象:top,left,right,bottom,loc和rect。

set the top of button 1 to 10 

如果你在1個多方向移動對象,你會想要做這樣的事情:

on moveObject 
    lock screen 
    lock messages 

    set the top of button 1 to 10 
    set the left of button 1 to 20 

    unlock messages 
    unlock screen 
end moveObject 

如果你想連續的動畫,你會想用,使之循環是這樣的:

on moveObject 
    lock screen 
    lock messages 

    local tX, tY 
    # Calculate new position (tX and tY) 

    # Move objects 
    set the loc of button 1 to tX, tY 

    unlock messages 
    unlock screen 

    # If animation is not finished, loop 
    if tEndCondition not true then 
     send "moveObject" to me in 5 milliseconds 
    end if 
end moveObject 

最後,如果你想要一個真正流暢的動畫,你會想擴大這個循環基於時間來計算對象的位置:

on animationLoop pTime 
    lock screen 
    lock messages 

    local tX, tY 
    # Calculate new position (tX and tY) based on time 

    # Move objects 
    set the loc of button 1 to tX, tY 

    unlock messages 
    unlock screen 

    if tEndCondition not true then 
     # Calculate when the next frame should be based on your target frame rate 
     send "moveObject" && tTime to me in tNextFrameTime 
    end if 
end animationLoop 

最後的方法提供了一種方法,如果某個幀花了很長時間來計算和渲染,那麼幀將被跳過。最終結果是一個反映用戶期望的平滑動畫。

1

如果你問如何使用箭頭鍵輕移對象,而在運行(瀏覽)模式,這裏是一個辦法(處理程序將進入卡腳本):

on arrowKey pWhich 
    # determine some way to designate which object is to be nudged 
    put the long id of btn "test" into tSelObj # for example 
    switch pWhich 
    case "left" 
     put -1 into tXamount 
     put 0 into tYamount 
     break 
    case "up" 
     put 0 into tXamount 
     put -1 into tYamount 
     break 
    case "right" 
     put 1 into tXamount 
     put 0 into tYamount 
     break 
    case "down" 
     put 0 into tXamount 
     put 1 into tYamount 
     break 
    end switch 
    move tSelObj relative tXamount,tYamount 
end arrowKey 
相關問題