Class: Sprite::Action
- Inherits:
-
Object
- Object
- Sprite::Action
- Defined in:
- lib/rmagick-sprite/action.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#current_index ⇒ Object
Returns the value of attribute current_index.
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sprite ⇒ Object
readonly
Returns the value of attribute sprite.
Instance Method Summary collapse
- #add_frame(options) ⇒ Object
- #current_frame ⇒ Object
- #current_image ⇒ Object
- #increase_index ⇒ Object
-
#initialize(options, &blk) ⇒ Action
constructor
A new instance of Action.
- #next_frame ⇒ Object
- #next_image ⇒ Object
- #write(filename, &blk) ⇒ Object
Constructor Details
#initialize(options, &blk) ⇒ Action
Returns a new instance of Action.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rmagick-sprite/action.rb', line 13 def initialize(, &blk) raise 'options must be a Hash' unless .respond_to?(:to_hash) || .respond_to?(:to_h) = .to_hash rescue .to_h raise 'options[:name] must be given' if [:name].nil? raise 'options[:sprite] must be given' if [:sprite].nil? raise 'options[:sprite] must be a Sprite' unless [:sprite].is_a?(Sprite) @sprite, @name = .values_at(:sprite, :name) @current_index, @frames = 0, [] DSL.call(self, &blk) end |
Instance Attribute Details
#current_index ⇒ Object
Returns the value of attribute current_index.
11 12 13 |
# File 'lib/rmagick-sprite/action.rb', line 11 def current_index @current_index end |
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
10 11 12 |
# File 'lib/rmagick-sprite/action.rb', line 10 def frames @frames end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/rmagick-sprite/action.rb', line 10 def name @name end |
#sprite ⇒ Object (readonly)
Returns the value of attribute sprite.
10 11 12 |
# File 'lib/rmagick-sprite/action.rb', line 10 def sprite @sprite end |
Instance Method Details
#add_frame(options) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rmagick-sprite/action.rb', line 27 def add_frame() raise 'options must be a Hash' unless .respond_to?(:to_hash) || .respond_to?(:to_h) = .to_hash rescue .to_h = { action: self }.merge(@sprite.).merge() @frames << Frame.new() end |
#current_frame ⇒ Object
34 35 36 |
# File 'lib/rmagick-sprite/action.rb', line 34 def current_frame @frames[@current_index] end |
#current_image ⇒ Object
38 39 40 |
# File 'lib/rmagick-sprite/action.rb', line 38 def current_image current_frame.image end |
#increase_index ⇒ Object
42 43 44 45 |
# File 'lib/rmagick-sprite/action.rb', line 42 def increase_index @current_index += 1 @current_index = 0 if @current_index >= @frames.length end |
#next_frame ⇒ Object
47 48 49 50 |
# File 'lib/rmagick-sprite/action.rb', line 47 def next_frame increase_index current_frame end |
#next_image ⇒ Object
52 53 54 55 |
# File 'lib/rmagick-sprite/action.rb', line 52 def next_image increase_index current_image end |
#write(filename, &blk) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rmagick-sprite/action.rb', line 57 def write(filename, &blk) image_list = Magick::ImageList.new @frames.each do |frame| image = frame.image image_list << image end blk.call(image_list) if block_given? image_list.write(filename) end |