Class: Carbuncle::AnimatedSprite
- Defined in:
- gems/carbuncle-graphics/mrblib/animated_sprite.rb
Overview
This class is an extension of a Sprite. Represents an Sprite, but instead of being manually handled, you just select the rows and columns. It also handles animations by name
Defined Under Namespace
Classes: Animation, AnimationSet
Instance Attribute Summary collapse
-
#animations ⇒ Object
readonly
Returns the value of attribute animations.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#sprite ⇒ Object
readonly
Returns the value of attribute sprite.
Instance Method Summary collapse
- #draw ⇒ Object
- #height ⇒ Object
-
#initialize(texture = nil) ⇒ AnimatedSprite
constructor
A new instance of AnimatedSprite.
- #texture=(value) ⇒ Object
- #update(dt) ⇒ Object
- #update_animation(dt) ⇒ Object
- #update_rect ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(texture = nil) ⇒ AnimatedSprite
Returns a new instance of AnimatedSprite.
79 80 81 82 83 84 85 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 79 def initialize(texture = nil) @sprite = Carbuncle::Sprite.new(texture) self.rows = 1 self.columns = 1 @frame = Carbuncle::Point.new @animations = Carbuncle::AnimatedSprite::AnimationSet.new end |
Instance Attribute Details
#animations ⇒ Object (readonly)
Returns the value of attribute animations.
77 78 79 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 77 def animations @animations end |
#columns ⇒ Object
Returns the value of attribute columns.
75 76 77 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 75 def columns @columns end |
#rows ⇒ Object
Returns the value of attribute rows.
74 75 76 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 74 def rows @rows end |
#sprite ⇒ Object (readonly)
Returns the value of attribute sprite.
76 77 78 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 76 def sprite @sprite end |
Instance Method Details
#draw ⇒ Object
109 110 111 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 109 def draw @sprite.draw end |
#height ⇒ Object
134 135 136 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 134 def height @frame_height end |
#texture=(value) ⇒ Object
138 139 140 141 142 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 138 def texture=(value) @sprite.texture = value @frame_width = texture.present? ? texture.width / rows : 1 @frame_height = texture.present? ? texture.height / columns : 1 end |
#update(dt) ⇒ Object
103 104 105 106 107 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 103 def update(dt) @sprite.update(dt) update_animation(dt) update_rect end |
#update_animation(dt) ⇒ Object
113 114 115 116 117 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 113 def update_animation(dt) animations.update(dt) @frame = animations.frame end |
#update_rect ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 119 def update_rect return unless texture.present? @sprite.src_rect.set( @frame.x * @frame_width, @frame.y * @frame_height, @frame_width, @frame_height ) end |
#width ⇒ Object
130 131 132 |
# File 'gems/carbuncle-graphics/mrblib/animated_sprite.rb', line 130 def width @frame_width end |