Class: RedBird::Animation::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/red_bird/animation.rb

Overview

Each frame has a sprite and a duration.

See Also:

Author:

  • Frederico Linhares

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(duration, sprite) ⇒ Frame

Returns a new instance of Frame.

Parameters:

  • duration (Integer)

    this animation frame will persist for as many game frames as defined by this value.

  • sprite (RedBird::Sprite)

    sprite to be displayed in this frame.

Author:

  • Frederico Linhares



20
21
22
23
# File 'lib/red_bird/animation.rb', line 20

def initialize(duration, sprite)
  @duration = duration
  @sprite = sprite
end

Instance Attribute Details

#durationInteger (readonly)

Returns how long this frame lasts.

Returns:

  • (Integer)

    how long this frame lasts.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/red_bird/animation.rb', line 13

class Frame
  attr_reader :duration, :sprite

  # @param duration [Integer] this animation frame will persist for as many
  #   game frames as defined by this value.
  # @param sprite [RedBird::Sprite] sprite to be displayed in this frame.
  # @author Frederico Linhares
  def initialize(duration, sprite)
    @duration = duration
    @sprite = sprite
  end

  # Create an array of frames and return it. This method must receive an
  # Array.
  #
  # @param frames [Array] each object in it must be an array containing the
  #   attributes for each frame returned.
  # @author Frederico Linhares
  def self.sequence(frames)
    return frames.collect { |i| Frame.new(i[0], i[1]) }
  end
end

#spriteRedBird::Sprite (readonly)

Returns sprite to display in this frame.

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/red_bird/animation.rb', line 13

class Frame
  attr_reader :duration, :sprite

  # @param duration [Integer] this animation frame will persist for as many
  #   game frames as defined by this value.
  # @param sprite [RedBird::Sprite] sprite to be displayed in this frame.
  # @author Frederico Linhares
  def initialize(duration, sprite)
    @duration = duration
    @sprite = sprite
  end

  # Create an array of frames and return it. This method must receive an
  # Array.
  #
  # @param frames [Array] each object in it must be an array containing the
  #   attributes for each frame returned.
  # @author Frederico Linhares
  def self.sequence(frames)
    return frames.collect { |i| Frame.new(i[0], i[1]) }
  end
end

Class Method Details

.sequence(frames) ⇒ Object

Create an array of frames and return it. This method must receive an Array.

Parameters:

  • frames (Array)

    each object in it must be an array containing the attributes for each frame returned.

Author:

  • Frederico Linhares



31
32
33
# File 'lib/red_bird/animation.rb', line 31

def self.sequence(frames)
  return frames.collect { |i| Frame.new(i[0], i[1]) }
end