Basic Motion and Transitions
基本運動和轉換
One of the most powerful things about the Corona SDK is that any display object can be animated. This is a testament to the flexible graphics model that Corona offers.
其中最強大的東西有關Corona SDK的是,任何顯示對象可以是動畫。這是一個證明了靈活的圖形模型,Corona 優惠。
Animations allow you to create visually-rich and engaging user experiences. Animations are accomplished by generating a sequence of frames that evolve smoothly from frame to frame. The term tween (short for inbetween) is a term describing the process in which such intermediate frames are generated. It is often used as shorthand to indicate that a property of an object will change during the animation, as in tweening the position.
動畫讓你創建視覺效果豐富,引人入勝的用戶體驗。動畫過程是通過產生一個序列平滑演進的幀幀與幀。這個詞之間(簡稱插圖中)是一個術語描述的過程中產生這些中間幀。它經常被用來作為縮寫,表示一個對象的屬性將改變在動畫,如在補間的立場。
Transitions 轉換
The transition library allows you to easily create animations with only a single line of code by allowing you to tween one or more properties of a display object. For example, you can fadeout a display object by tweening its alpha property (the alpha property transitions from 1.0 to 0).
轉換庫允許您輕鬆地創建動畫,只有一行的代碼,讓您一個或多個屬性之間的顯示對象。例如,您可以淡出顯示其α補間對象屬性(從 1.0 alpha屬性轉換為 0)。
The simplest way to do this is to use the transition.to method which takes a display object as its first argument and a table containing the control parameters as its second. The control parameters specify the duration of the animation, an optional delay for when to start the animation, and the final values of properties for the display object. The intermediate values for a property are determined by an easing function that is also specified as a control parameter. By default this is a linear function.
最簡單的方式做,這是使用方法,需要一個 transition.to顯示對象作為它的第一個參數,一個包含了控制參數作為其第二個。控制參數指定的期限動畫,可選延遲何時開始動畫,最終值屬性的顯示對象。中間值的屬性是由一個緩和功能,也被指定為控制參數。默認情況下這是一個線性函數。
Below are some examples of how to animate a square (see Transition2 in the sample code):
下面是一些例子如何動畫一個正方形(見 Transition2在示例代碼):
local square = display.newRect( 0, 0, 100, 100 ) square:setFillColor( 255,255,255 ) local w,h = display.contentWidth, display.contentHeight local square = display.newRect( 0, 0, 100, 100 ) square:setFillColor( 255,255,255 ) local w,h = display.contentWidth, display.contentHeight -- (1) move square to bottom right corner; subtract half side-length -- b/c the local origin is at the square's center; fade out square transition.to( square, { time=1500, alpha=0, x=(w-50), y=(h-50) } ) -- (2) fade square back in after 2.5 seconds transition.to( square, { time=500, delay=2500, alpha=1.0 } )
In the first tween, notice that multiple values are changing: position and alpha. That’s because in the control parameters we specified the final values for the x, y, and alpha properties. 在第一個補間,發現多個值正在改變:位置和alpha。這是因為在我們的控制參數中指定的最終值的X,Y和alpha屬性。
For each property specified in the control parameters, the library looks at the current property value and gradually changes that property to the final value over the time period specified (1.5 seconds in this case). In the last tween, we use the delay control parameter to start the tween after the initial tween’s fadeout is complete.
對於每個屬性中指定的控制參數,library著眼於當前的屬性值,並逐步改變,到最後的屬性值超過指定的時間段(在這個例子是1.5秒)。在過去的補間,我們使用延遲控制參數,補間開始,最初之間的淡出已完成。
Note that the transition library operates in a time-based manner.
請注意,轉換庫工作在基於時間的方式。
transition.to( target, params )
Returns a tween that animates properties in the display object target over time. The final property values are specified in the params table. To customize the tween, you can optionally specify the following non-animating properties in params:
返回一個補間動畫的顯示對象中的屬性目標隨著時間的推移。最後一個屬性值中指定的參數表。要自補間,您可以選擇指定的下列非動畫特性參數:
*params.time specifies the duration of the transition in milliseconds. By default, the duration is 500 ms (0.5 seconds).
*params.transition is by default easing.linear . See Easing for more functions.
*params.delay specifies the delay (none by default) before the tween begins.
*params.delta is a boolean specifying whether non-control parameters are interpreted as final ending values or as changes in value. The default is nil meaning false.
*params.onStart is a function or table listener called before the tween begins. Table listeners must have an onStart method. When invoked, the listener is given target instead of an event.
*params.onComplete is a function or table listener called after the tween completes.
* params.time指定的時間以毫秒為單位的過渡。默認情況下,持續時間為 500毫秒(0.5秒)。
* params.transition默認 easing.linear。見放寬更多的功能。
* params.delay指定的延遲(無默認)補間開始之前。
* params.delta是一個布爾值,指定是否非控制參數被解釋為最終結束值或值的變化。默認值是零的意思假的。
* params.onStart是一個函數之前調用偵聽器或表補間開始。表聽眾必須有一個 OnStart方法。調用時,聽者是給定的目標,而不是一個事件。
* params.onComplete是一個函數或表後調用偵聽器之間完成。
例子:--------------------------------------------------------------
