2014-07-17 71 views
3

我一直在使用LiveCode幾天,但我發現一個問題,並一直堅持了一整天。加速旋轉圖像 - LiveCode

我的項目是財富遊戲的輪盤/輪,其中一個圓形圖像的旋轉度隨機量和中心的靜態針/北標誌着其下的當前部分。

爲了使圖像旋轉,我用一個按鈕,這個代碼:

on mouseUp 
    put random(360) into i 
    repeat with x=0 to i 
    set the angle of image "ruleta.png" to the angle of image "ruleta.png" + 1 
    wait for 10 milliseconds 
    end repeat 
end mouseUp 

的問題是,我可以使圖像旋轉,但只有達到一定的速度,並沒有外表光滑的所有。有沒有辦法增加每秒的幀數?如果它能夠自然旋轉加速/減速,我會很棒。

增加的程度它旋轉每一幀,使它看起來更快速的量,但很不穩定。

此外,RunDev論壇給我重定向在Chrome,Firefox和Safari循環和404的,關閉大部分的信息穀歌給我的訪問。這是否發生在每個人身上?

回答

2

使用由用戶本傑明·博蒙特(再次感謝!)提供的代碼,我得到了它運行像我想要的。爲了給它平滑運動和減速,我用下面的代碼:

on mouseUp 
    put randomInRange(15,45) into i 
    set the resizeQuality of image 1 to "normal" 
    put 0 into mi 
    repeat with x=0 to i 
    set the angle of image 1 to the angle of image 1 + (i - mi) 
    put mi+1 into mi 
    wait for 10 milliseconds 
    end repeat 
    lock screen 
    set the resizeQuality of image 1 to "best" 
    set the angle of image 1 to the angle of image 1 + 1 
    set the angle of image 1 to the angle of image 1 - 1 
    unlock screen 
end mouseUp 

減速完全是線性的,但看起來只有精細,注意randomInRange不是LiveCode功能,如果有人想它,那就是:

function randomInRange lowerLimit,upperLimit 
    return random(upperLimit - lowerLimit + 1) + lowerLimit - 1 
end randomInRange 
5

當我在我的蘋果機上的圖像上嘗試代碼時,它很好,很流暢。我會假設你正在開發一款移動應用程序。

首先要說的是,圖像旋轉是即時計算的。這意味着每次設置圖像的能力時,LiveCode都會重新計算圖像的所有像素,而這些像素相當昂貴。在臺式機上,你有一個非常強大的CPU,因此旋轉圖像相當容易處理並且看起來很流暢,但移動設備的CPU並不強大,並且難以應付這種操作。

可能的解決方案1 ​​ - LiveCode考慮到圖像的「resizeQuality」屬性。您可以將其設置爲「正常」,「良好」和「最佳」,最快的是「正常」,從而產生塊狀圖像,最慢的是「更好」,質量更高。如果您正在使用更高質量的設置,則可以在旋轉發生時通過臨時降低質量來提高性能。

on mouseUp 
    put random(360) into i 
    set the resizeQuality of image 1 to "normal" 
    repeat with x=0 to i 
     set the angle of image 1 to the angle of image 1 + 1 
     wait for 10 milliseconds 
    end repeat 

    lock screen 
    set the resizeQuality of image 1 to "best" 
    set the angle of image 1 to the angle of image 1 + 1 
    set the angle of image 1 to the angle of image 1 - 1 
    unlock screen 
end mouseUp 

請注意,要使圖像以高質量重繪,我已經改變了角度。

可能的解決方案2 - 如果你不能得到足夠的性能,最好的事情是在所有360位來生成你的車輪圖像。然後,您可以正確地將圖像的文件名設置爲正確的文件名。

local tImagesPath 
set the itemdel to "/" 
put item 1 to -2 of the filename of this stack & slash & "wheel_images" & slash into tImagesPath 

set the resizeQuality of image 1 to "best" 

repeat with x=0 to 359 
    set the angle of image 1 to x 
    export snapshot from image 1 to file tImagesPath & x & ".png" as png 
    wait 1 millisecond with messages 
end repeat 

該腳本在359個位置生成高質量的車輪圖像。

在移動獲得良好的性能,當你打開應用程序,重複通過在359個位置的車輪的所有圖像,並呼籲:

prepare image 

這將導致LiveCode預加載圖像到內存使它可能會呈現一些非常流暢的動畫。

+0

Thanks!第一種解決方案使其具有相同的速度,我不會爲任何易移動設備構建,而我正在使用帶有1GB視頻卡和16克RAM的OSX,因此不會是問題,可以嗎? 第二個解決方案給我一個錯誤(無法打開文件(或標記文件)附近的[圖像的路徑]。這段代碼進入按鈕,對吧? – TianRB

+0

啊,這將是因爲它無法找到文件夾..我在我的LiveCode堆棧文件旁邊手動創建它。 –