Class: Sprite
- Inherits:
-
Object
- Object
- Sprite
- Defined in:
- lib/rmagick-sprite.rb,
lib/rmagick-sprite/frame.rb,
lib/rmagick-sprite/action.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#default_action ⇒ Object
Returns the value of attribute default_action.
-
#default_action_options ⇒ Object
Returns the value of attribute default_action_options.
-
#default_frame_options ⇒ Object
Returns the value of attribute default_frame_options.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #add_action(name, options = {}, &blk) ⇒ Object
- #current_frame ⇒ Object
- #current_image ⇒ Object
- #image ⇒ Object
-
#initialize(&blk) ⇒ Sprite
constructor
A new instance of Sprite.
- #next_frame ⇒ Object
- #next_image ⇒ Object
- #reload ⇒ Object
Constructor Details
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
17 18 19 |
# File 'lib/rmagick-sprite.rb', line 17 def action @action end |
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
17 18 19 |
# File 'lib/rmagick-sprite.rb', line 17 def actions @actions end |
#default_action ⇒ Object
Returns the value of attribute default_action.
18 19 20 |
# File 'lib/rmagick-sprite.rb', line 18 def default_action @default_action end |
#default_action_options ⇒ Object
Returns the value of attribute default_action_options.
18 19 20 |
# File 'lib/rmagick-sprite.rb', line 18 def @default_action_options end |
#default_frame_options ⇒ Object
Returns the value of attribute default_frame_options.
18 19 20 |
# File 'lib/rmagick-sprite.rb', line 18 def @default_frame_options end |
#filename ⇒ Object
Returns the value of attribute filename.
17 18 19 |
# File 'lib/rmagick-sprite.rb', line 17 def filename @filename end |
Instance Method Details
#add_action(name, options = {}, &blk) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/rmagick-sprite.rb', line 71 def add_action(name, ={}, &blk) raise 'options must be a Hash' unless .respond_to?(:to_hash) || .respond_to?(:to_h) = .to_hash rescue .to_h = { sprite: self, name: name }.merge(@default_action_options).merge() @actions[name] = Action.new(, &blk) end |
#current_frame ⇒ Object
93 94 95 |
# File 'lib/rmagick-sprite.rb', line 93 def current_frame action.current_frame end |
#current_image ⇒ Object
97 98 99 |
# File 'lib/rmagick-sprite.rb', line 97 def current_image action.current_image end |
#image ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rmagick-sprite.rb', line 79 def image raise 'filename must be set' if @filename.nil? reload if @image.nil? @image end |
#next_frame ⇒ Object
101 102 103 |
# File 'lib/rmagick-sprite.rb', line 101 def next_frame action.next_frame end |
#next_image ⇒ Object
105 106 107 |
# File 'lib/rmagick-sprite.rb', line 105 def next_image action.next_image end |
#reload ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rmagick-sprite.rb', line 86 def reload @image = Magick::Image.read(@filename).first @actions.each { |name, action| action.frames.each(&:reload) } @image end |