Module: Chingu::Traits::Animation
- Defined in:
- lib/chingu/traits/animation.rb
Overview
A chingu trait providing automatic loading of tile-animations
For example: class FireBall; has_traits :animation; end;
Will automatically load:
-
fire_ball.png into self.animations
-
fire_ball_exploding.png into self.animations
Adds accessors animations -> Hash with all animations, hash-key is the name of the animation
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #animation ⇒ Object
-
#animations ⇒ Object
Returns all animations, then access invidual states with animations etc.
-
#load_animations ⇒ Object
Try loading animation from class-name.
- #setup_trait(options) ⇒ Object
Instance Method Details
#animation ⇒ Object
73 74 75 |
# File 'lib/chingu/traits/animation.rb', line 73 def animation @animations[:default] end |
#animations ⇒ Object
Returns all animations, then access invidual states with animations etc.
80 81 82 |
# File 'lib/chingu/traits/animation.rb', line 80 def animations @animations end |
#load_animations ⇒ Object
Try loading animation from class-name
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chingu/traits/animation.rb', line 55 def load_animations animations = {} glob = "#{[:animation][:directory]}/#{self.filename}*" puts "Animations? #{glob}" if [:animation][:debug] Dir[glob].each do |tile_file| puts tile_file if [:animation][:debug] if tile_file =~ /[a-zA-Z\_+]_*(\d+)x(\d+)_*([a-zA-Z]*)\.(bmp|png)/ state = $3.length > 0 ? $3 : "default" animations[state.to_sym] = Chingu::Animation.new([:animation].merge(:file => tile_file)) elsif tile_file =~ /[a-zA-Z\_+]\.(bmp|png)/ puts tile_file animations[:default] = Chingu::Animation.new([:animation].merge(:file => tile_file)) end end return animations end |
#setup_trait(options) ⇒ Object
46 47 48 49 50 |
# File 'lib/chingu/traits/animation.rb', line 46 def setup_trait() @animation_options = {:debug => false}.merge() @animations = load_animations super end |