|
|
-
- TweenFunc = TweenFunc or {}
- local TweenFunc = TweenFunc
- TweenFunc.LINEAR = "linear" --线性
- TweenFunc.EASE_IN = "easeIn"
- TweenFunc.EASE_OUT = "easeOut"
- TweenFunc.EASE_IN_OUT = "easeInOut"
- TweenFunc.EASE_OUT_IN = "easeOutIn"
- TweenFunc.EASE_IN_BACK = "easeInBack"
- TweenFunc.EASE_OUT_BACK = "easeOutBack"
- TweenFunc.EASE_IN_OUT_BACK = "easeInOutBack"
- TweenFunc.EASE_OUT_IN_BACK = "easeOutInBack"
- TweenFunc.EASE_IN_ELASTIC = "easeInElastic"
- TweenFunc.EASE_OUT_ELASTIC = "easeOutElastic"
- TweenFunc.EASE_IN_OUT_ELASTIC = "easeInOutElastic"
- TweenFunc.EASE_OUT_IN_ELASTIC = "easeOutInElastic"
- TweenFunc.EASE_IN_BOUNCE = "easeInBounce"
- TweenFunc.EASE_OUT_BOUNCE = "easeOutBounce"
- TweenFunc.EASE_IN_OUT_BOUNCE = "easeInOutBounce"
- TweenFunc.EASE_OUT_IN_BOUNCE = "easeOutInBounce"
- TweenFunc.EASE_IN_TO_OUT_BACK = "easeInToOutBack"
- TweenFunc.PINGPONG = "pingPong"
- TweenFunc.EASE_OUT_QUINT = "easeOutQuint"
- TweenFunc.EASE_IN_QUINT = "easeInQuint"
-
- function TweenFunc.linear(ratio)
- return ratio
- end
- function TweenFunc.easeIn(ratio)
- return ratio * ratio * ratio
- end
- function TweenFunc.easeOut(ratio)
- local invRatio = ratio - 1.0
- return invRatio * invRatio * invRatio + 1
- end
- function TweenFunc.easeInOut(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeIn, TweenFunc.easeOut, ratio)
- end
- function TweenFunc.easeOutIn(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeOut, TweenFunc.easeIn, ratio)
- end
- function TweenFunc.easeInBack(ratio)
- local s = 1.70158
- return ratio * ratio * ((s + 1.0)*ratio - s)
- end
- function TweenFunc.easeOutBack(ratio)
- local invRatio = ratio - 1.0
- local s = 1.70158
- return invRatio * invRatio * ((s + 1.0)*invRatio + s) + 1.0
- end
- function TweenFunc.easeInOutBack(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeInBack, TweenFunc.easeOutBack, ratio)
- end
- function TweenFunc.easeOutInBack(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeOutBack, TweenFunc.easeInBack, ratio)
- end
- function TweenFunc.easeInElastic(ratio)
- if ratio == 0 or ratio == 1 then
- return ratio
- else
- local p = 0.3
- local s = p/4.0
- local invRatio = ratio - 1
- return -1.0 * math.pow(2.0, 10.0*invRatio) * math.sin((invRatio-s)*(2.0*math.pi)/p)
- end
- end
- function TweenFunc.easeOutElastic(ratio)
- if ratio == 0 or ratio == 1 then
- return ratio
- else
- local p = 0.3
- local s = p/4.0
- return math.pow(2.0, -10.0*ratio) * math.sin((ratio-s)*(2.0*math.pi)/p) + 1
- end
- end
- function TweenFunc.easeInOutElastic(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeInElastic, TweenFunc.easeOutElastic, ratio)
- end
- function TweenFunc.easeOutInElastic(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeOutElastic, TweenFunc.easeInElastic, ratio)
- end
- function TweenFunc.easeInBounce(ratio)
- return 1.0 - TweenFunc.easeOutBounce(1.0 - ratio)
- end
- function TweenFunc.easeOutBounce(ratio)
- local s = 7.5625
- local p = 2.75
- local l = nil
- if ratio < (1.0/p) then
- l = s * math.pow(ratio, 2)
- else
- if ratio < (2.0/p) then
- ratio = ratio - 1.5/p
- l = s * math.pow(ratio, 2) + 0.75
- else
- if ratio < 2.5/p then
- ratio = ratio - 2.25/p
- l = s * math.pow(ratio, 2) + 0.9375
- else
- ratio = ratio - 2.625/p
- l = s * math.pow(ratio, 2) + 0.984375
- end
- end
- end
- return l
- end
- function TweenFunc.easeInOutBounce(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeInBounce, TweenFunc.easeOutBounce, ratio)
- end
- function TweenFunc.easeOutInBounce(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeOutBounce, TweenFunc.easeInBounce, ratio)
- end
- function TweenFunc.easeInToOutBack(ratio)
- return TweenFunc.easeCombined(TweenFunc.easeIn, TweenFunc.easeOutBack, ratio)
- end
- function TweenFunc.easeCombined(startFunc, endFunc, ratio)
- if ratio < 0.5 then
- return 0.5 * startFunc(ratio*2.0)
- else
- return 0.5 * endFunc((ratio-0.5)*2.0) + 0.5
- end
- end
- function TweenFunc.pingPong(ratio)
- if ratio < 0.5 then
- return TweenFunc.linear(ratio * 2)
- else
- return TweenFunc.linear( 2 - ratio * 2 )
- end
- end
- function TweenFunc.easeOutQuint(ratio)
- local invRatio = ratio - 1.0
- return invRatio * invRatio * invRatio * invRatio * invRatio + 1
- end
- function TweenFunc.easeInQuint(ratio)
- return ratio * ratio * ratio * ratio
- end
-
- TweenFunc[TweenFunc.LINEAR] = TweenFunc.linear
- TweenFunc[TweenFunc.EASE_IN] = TweenFunc.easeIn
- TweenFunc[TweenFunc.EASE_OUT] = TweenFunc.easeOut
- TweenFunc[TweenFunc.EASE_IN_OUT] = TweenFunc.easeInOut
- TweenFunc[TweenFunc.EASE_OUT_IN] = TweenFunc.easeOutIn
- TweenFunc[TweenFunc.EASE_IN_BACK] = TweenFunc.easeInBack
- TweenFunc[TweenFunc.EASE_OUT_BACK] = TweenFunc.easeOutBack
- TweenFunc[TweenFunc.EASE_IN_OUT_BACK] = TweenFunc.easeInOutBack
- TweenFunc[TweenFunc.EASE_OUT_IN_BACK] = TweenFunc.easeOutInBack
- TweenFunc[TweenFunc.EASE_IN_ELASTIC] = TweenFunc.easeInElastic
- TweenFunc[TweenFunc.EASE_OUT_ELASTIC] = TweenFunc.easeOutElastic
- TweenFunc[TweenFunc.EASE_IN_OUT_ELASTIC] = TweenFunc.easeInOutElastic
- TweenFunc[TweenFunc.EASE_OUT_IN_ELASTIC] = TweenFunc.easeOutInElastic
- TweenFunc[TweenFunc.EASE_IN_BOUNCE] = TweenFunc.easeInBounce
- TweenFunc[TweenFunc.EASE_OUT_BOUNCE] = TweenFunc.easeOutBounce
- TweenFunc[TweenFunc.EASE_IN_OUT_BOUNCE] = TweenFunc.easeInOutBounce
- TweenFunc[TweenFunc.EASE_OUT_IN_BOUNCE] = TweenFunc.easeOutInBounce
- TweenFunc[TweenFunc.EASE_IN_TO_OUT_BACK] = TweenFunc.easeInToOutBack
- TweenFunc[TweenFunc.PINGPONG] = TweenFunc.pingPong
- TweenFunc[TweenFunc.EASE_OUT_QUINT] = TweenFunc.easeOutQuint
- TweenFunc[TweenFunc.EASE_IN_QUINT] = TweenFunc.easeInQuint
|