我正在使用以下緩和功能在屏幕上移動對象的一個項目:防止出界值的彭納緩解
function easeinoutquart(t,b,c,d) as float
't=time, b=startvalue, c=change in value, d=duration
d=d/2
t=t/d
if (t < 1) then
return c/2*t*t*t*t + b
end if
t=t-2
return -c/2 * (t*t*t*t - 2) + b
end function
我一直運行到其中的值去迅速出的情況下,導致物體以令人眩暈的速度離開屏幕。第一種情況似乎是由於將函數的結果截斷爲整數值而導致的,我修正了這個結果。觸發完全相同行爲的下一件事似乎是在對象停止並輸入新的緩動距離後,時間值未被重置。一旦我在更改目標值(change = destination-start)後添加了重置,這似乎完全解決了問題。
現在我已經添加了更多的代碼來下載和交換圖像的循環。看起來,在循環中增加的執行時間有時會導致值超出界限,從而產生相同的圖像模糊,從畫面中跳出。
簡要說明代碼:
loop
check for user input (up down left right select)
if so set new dest position for all images, reset timer for all images
if a new image is selected on screen, load related content, reset related content timer
is there an image in the queue to download? if so get initiate async download
are any images downloaded? If so swap out temp image with final image
call easing function for primary images (vertical movement on y axis)
call easing function for related content (horizontal movement on x axis)
draw all graphics and swap display buffer
end loop
之前將圖像下載/交換(實際交換隻是改變一個指針)的代碼,一切都既預裝的圖像和溫度圖像偉大的工作。現在我首先加載臨時映像並交換,我認爲循環有時候會在超過1/30秒的時間內執行,也許這會導致定時器值變得奇怪。
所以基本上,我想知道是否有某種「管理者」鉗位我可以把價值觀,將保持緩和功能,以產生瘋狂的價值觀,迅速失控。例如,在一次迭代中移動的總距離應該不超過250個像素,實際上應該總是朝目標值僅幾個像素。