Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module DSI_Tween
- def self.linear(t, b, c, d)
- return b + c * (t/d.to_f)
- end
- def self.easeInOutQuart(t, b, c, d)
- if (t/=d/2.0) < 1
- return c/2*t*t*t*t + b
- end
- return -c/2 * ((t-=2)*t*t*t - 2) + b
- end
- end
- class Scene_Base
- alias_method(:dsi_tween_update, :update)
- def tween(obj, params, duration, &callback)
- @tween_objects ||= []
- tween_obj = {}
- tween_obj[:target] = obj
- tween_obj[:params] = []
- params.each do |data|
- begin_value = eval("tween_obj[:target].#{data[0].to_s}")
- change = data[1] - begin_value
- obj = [data[0].to_s, begin_value, change]
- tween_obj[:params] << obj
- end
- tween_obj[:duration] = duration
- tween_obj[:timer] = 0
- tween_obj[:callback] = callback if callback
- @tween_objects << tween_obj
- tween_obj[:easing] = :easeInOutQuart
- return tween_obj
- end
- def update
- dsi_tween_update
- update_tween_objects
- end
- def update_tween_objects
- return unless @tween_objects
- new_tweens = []
- @tween_objects.each do |tween_object|
- target = tween_object[:target]
- params = tween_object[:params]
- duration = tween_object[:duration]
- if tween_object[:timer] < duration
- params.each do |data|
- case tween_object[:easing]
- when :easeInOutQuart
- new_value = DSI_Tween.easeInOutQuart(tween_object[:timer], data[1], data[2], duration)
- when :linear
- new_value = DSI_Tween.linear(tween_object[:timer], data[1], data[2], duration)
- end
- eval("target.#{data[0]} = new_value")
- end
- tween_object[:timer] += 1
- new_tweens << tween_object
- else
- tween_object[:callback].call() if tween_object[:callback]
- end
- end
- @tween_objects = new_tweens
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement