Class: TDD::Ease
- Inherits:
-
Object
- Object
- TDD::Ease
- Defined in:
- TDD Easing/tdd_ease_module.rb
Overview
- Summary
-
This static class is used to apply an easing algorithm to an object's parameters over X amount of frames.
Easing methods can be extended through adding static methods to the Easing module. The default easing method is Easing::LINEAR and is identical to the default easing provided in VXAce
- Version
-
1.0.9
- Date
-
03/24/2015
- Author
-
Galenmereth / Tor Damian Design <post@tordamian.com>
- License
-
Free for non-commercial and commercial use. Credit greatly appreciated but not required. Share script freely with everyone, but please retain this description area unless you change the script completely. Thank you.
Changelog
- 1.0.9
-
Updated Game_CharacterBase extension to 1.0.4, fixing ease_moveto_char problems when using event ids
-
- 1.0.8
-
Added Ease.complete_easings_for with options.
-
Fixed overwrite bug, so that it checks for pointer uniqueness when comparing two easing targets.
-
- 1.0.7
-
Added :overwrite option for Ease.to, Ease.from and Ease.register_ease called :overwrite, which will overwrite any other easings for the given target(s).
-
Added new public method: Ease.clear_easings_for. See its documentation
-
Moved the performing of an ease frame animation into separate method: Ease.perform_ease_for.
-
- 1.0.6
-
Added support to use non-Hash objects directly as targets of easing. This is fully backwards compatible. Also added documentation for the delay option.
- 1.0.5
-
Added support for a delay in options hash. This makes the easing wait the specified x amount of frames before starting.
- 1.0.4
-
TDD Ease Object updated. Ease.from now works as intended. Fixed attribute origin setting to remove method check, since that is done in the easing module already.
- 1.0.3
-
Fixed @interpreter bug in Game_CharacterBase extension
- 1.0.2
-
Introduced the TDD module namespace and Ease_Object instead of using a hash
Constant Summary
- @@easings =
[]
Class Method Summary (collapse)
-
+ (Object) clear_easings_for(args = {})
Clear all active easings for a target object.
-
+ (Object) complete_easings_for(target, perform_complete_call = false)
Complete easings for a target (or an array of targets).
-
+ (Ease_Object) from(target, frames, attributes = {}, options = {})
Ease parameters from given attribute values to target's current attribute values.
-
+ (Object) overwrite_other_easings(ease)
Overwrite other ease queues for Ease_Objects with the same target.
-
+ (Object) perform_ease_for(ease)
Perform ease for Ease_Object.
-
+ (Ease_Object) register_ease(method, target, frames, attributes, options)
Register an Ease_Object in queue.
-
+ (Ease_Object) to(target, frames, attributes = {}, options = {})
Ease parameters to given attribute values from target's current attribute values.
-
+ (Object) update
Updates easings every engine / Scene frame tick.
Class Method Details
+ (Object) clear_easings_for(args = {})
Clear all active easings for a target object
230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'TDD Easing/tdd_ease_module.rb', line 230 def clear_easings_for(args={}) args = { :target => nil, :perform_complete_call => false }.merge(args) @@easings.each do |ease| @@easings.delete(ease) if ease.target.equal?(args[:target]) if args[:perform_complete_call] ease.observers.each{|o| o.send(ease.call_on_complete, ease)} if ease.call_on_complete end end end |
+ (Object) complete_easings_for(target, perform_complete_call = false)
Complete easings for a target (or an array of targets). Skips directly to the last “frame” of transition.
248 249 250 251 252 253 254 255 256 257 |
# File 'TDD Easing/tdd_ease_module.rb', line 248 def complete_easings_for(target, perform_complete_call=false) if target.is_a? Array target.each{|t| complete_easings_for(t, perform_complete_call)} else @@easings.select{|e| e.target == target}.each do |ease| ease.frames = 1 perform_ease_for(ease) end end end |
+ (Ease_Object) from(target, frames, attributes = {}, options = {})
Functions like to, except eases from given attributes values to current target attribute values
Ease parameters from given attribute values to target's current attribute values
109 110 111 |
# File 'TDD Easing/tdd_ease_module.rb', line 109 def from(target, frames, attributes={}, ={}) register_ease(:from, target, frames, attributes, ) end |
+ (Object) overwrite_other_easings(ease)
Overwrites (deletes) other Ease_Objects with the same target
Overwrite other ease queues for Ease_Objects with the same target
213 214 215 216 217 218 219 220 221 222 223 |
# File 'TDD Easing/tdd_ease_module.rb', line 213 def overwrite_other_easings(ease) return unless ease.overwrite # Turn off overwrite from now for this ease ease.overwrite = false # Remove other ease with same target @@easings.each do |ease_to_delete| @@easings.delete(ease_to_delete) if ease_to_delete.target.equal?(ease.target) && ease_to_delete != ease end end |
+ (Object) perform_ease_for(ease)
Perform ease for Ease_Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'TDD Easing/tdd_ease_module.rb', line 136 def perform_ease_for(ease) # Initial setup of origin attributes ease.setup # Set local target var target = ease.target begin # Perform easing ease.attributes.each_pair do |attribute, value| attribute_origin = ease.attributes_origin[attribute] case ease.method when :to from = attribute_origin to = value when :from from = value to = attribute_origin end # Move instantly if frames is 1 if ease.frames == 1 value = to else value = Easing.send(ease.easing, ease.frame, from, to - from, ease.frames) end # Set the attribute on the target if target.is_a? Hash target[attribute] = value else target.send("#{attribute}=", value) end end ease.observers.each{|o| o.send(ease.call_on_update, ease)} if ease.call_on_update ease.frame += 1 if ease.frame > ease.frames @@easings.delete(ease) ease.observers.each{|o| o.send(ease.call_on_complete, ease)} if ease.call_on_complete end rescue # Do not attempt to animate disposed items clear_easings_for(target: target) if target.class.method_defined?("disposed?") && target.disposed? end end |
+ (Ease_Object) register_ease(method, target, frames, attributes, options)
Register an Ease_Object in queue
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'TDD Easing/tdd_ease_module.rb', line 189 def register_ease(method, target, frames, attributes, ) if target.is_a? Array target.each{|target| self.register_ease(method, target, frames, attributes, )} return end ease = TDD::Ease_Object.new(method, target, frames, attributes, ) # Perform initial ease this frame if no delay perform_ease_for(ease) if ease.delay == 0 && method == :from # Delete other easings for same target if applicable self.overwrite_other_easings(ease) if ease.overwrite && ease.delay == 0 # Add to easings array @@easings.push(ease) end |
+ (Ease_Object) to(target, frames, attributes = {}, options = {})
Depending on how your objects or classes are set up, you may need to use an “intermediary” object (like the target_obj hash in the example) to hold the attributes, then apply the values form this “intermediary” object to the attributes of the class when the :call_on_update method is called. The reason for this is that you may not necessarily want the easing function to write directly to a caller class. Look at the Game_Picture extension for an example of this necessity, where I didn't want to make any of the read-only attributes writable to implement easing.
Ease parameters to given attribute values from target's current attribute values
97 98 99 |
# File 'TDD Easing/tdd_ease_module.rb', line 97 def to(target, frames, attributes={}, ={}) register_ease(:to, target, frames, attributes, ) end |
+ (Object) update
Called by Scene_Base when the extension is in place for it.
Updates easings every engine / Scene frame tick
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'TDD Easing/tdd_ease_module.rb', line 117 def update @@easings.each do |ease| # Skip to wait for delay option if present if ease.delay > 0 ease.delay -= 1 next end # Delete other easings if overwrite set self.overwrite_other_easings(ease) if ease.overwrite # Perform ease calculations perform_ease_for(ease) end end |