Module: OR2D::Animations::CompositeAnimations

Included in:
Composites::Sprite, Composites::Text
Defined in:
lib/or2d/animations/composite_animations.rb

Overview

A module that provides functions for animating the layers of a Composite object.

Since:

  • 2023-04-26

Instance Method Summary collapse

Instance Method Details

#fade(speed: nil, target: :all) ⇒ Object

Fade the a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • speed (Float) (defaults to: nil)

    the speed at which to fade

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to fade or :all to fade all layers

Since:

  • 2023-04-26



9
10
11
12
13
14
15
16
17
# File 'lib/or2d/animations/composite_animations.rb', line 9

def fade(speed: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].fade(speed: speed)
    end
  else
    OR2D.game.entities[@layers.keys[target]].fade(speed: speed)
  end
end

#fade_in(speed: nil, target: :all) ⇒ Object

Fade in a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • speed (Float) (defaults to: nil)

    the speed at which to fade in

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to fade in or :all to fade in all layers

Since:

  • 2023-04-26



22
23
24
25
26
27
28
29
30
# File 'lib/or2d/animations/composite_animations.rb', line 22

def fade_in(speed: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].fade_in(speed: speed)
    end
  else
    OR2D.game.entities[@layers.keys[target]].fade_in(speed: speed)
  end
end

#fade_out(speed: nil, target: :all) ⇒ Object

Fade out a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • speed (Float) (defaults to: nil)

    the speed at which to fade out

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to fade out or :all to fade out all layers

Since:

  • 2023-04-26



35
36
37
38
39
40
41
42
43
# File 'lib/or2d/animations/composite_animations.rb', line 35

def fade_out(speed: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].fade_out(speed: speed)
    end
  else
    OR2D.game.entities[@layers.keys[target]].fade_out(speed: speed)
  end
end

#grow(factor: 1.0, delay: 100, target: :all) ⇒ Object

Grow a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: 1.0)

    the factor by which to grow

  • delay (Integer) (defaults to: 100)

    the delay before growing

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to grow or :all to grow all layers

Since:

  • 2023-04-26



64
65
66
67
68
69
70
71
72
# File 'lib/or2d/animations/composite_animations.rb', line 64

def grow(factor: 1.0, delay: 100, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].grow(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].grow(factor: factor, delay: delay)
  end
end

#grow_entity(factor: nil, delay: nil, target: :all) ⇒ Object

Grow the entity of a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: nil)

    the factor by which to grow the entity

  • delay (Integer) (defaults to: nil)

    the delay before growing the entity

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to grow the entity or :all to grow the entity of all layers

Since:

  • 2023-04-26



92
93
94
95
96
97
98
99
100
# File 'lib/or2d/animations/composite_animations.rb', line 92

def grow_entity(factor: nil, delay: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].grow_entity(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].grow_entity(factor: factor, delay: delay)
  end
end

#grow_text_composite(factor: nil, delay: nil, target: :all) ⇒ Object

Grow the text of a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: nil)

    the factor by which to grow the text

  • delay (Integer) (defaults to: nil)

    the delay before growing the text

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to grow the text or :all to grow the text of all layers

Since:

  • 2023-04-26



78
79
80
81
82
83
84
85
86
# File 'lib/or2d/animations/composite_animations.rb', line 78

def grow_text_composite(factor: nil, delay: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].grow_text(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].grow_text(factor: factor, delay: delay)
  end
end

#rotation(speed: 0.1, angle: 360, clockwise: true, target: :all) ⇒ Object

Rotate a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • speed (Float) (defaults to: 0.1)

    the speed at which to rotate

  • angle (Float) (defaults to: 360)

    the angle at which to rotate

  • clockwise (Boolean) (defaults to: true)

    whether to rotate clockwise or counter-clockwise

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to rotate or :all to rotate all layers

Since:

  • 2023-04-26



50
51
52
53
54
55
56
57
58
# File 'lib/or2d/animations/composite_animations.rb', line 50

def rotation(speed: 0.1, angle: 360, clockwise: true, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].rotation(speed: speed, angle: angle, clockwise: clockwise)
    end
  else
    OR2D.game.entities[@layers.keys[target]].rotation(speed: speed, angle: angle, clockwise: clockwise)
  end
end

#shake(target: :all, duration: 100, magnitude: 10) ⇒ Object

Shake a single layer of a Composite object, or all layers if no target is specified.

Examples:

Shake all layers of a Composite object

Parameters:

  • duration (Integer) (defaults to: 100)

    the duration of the shake

  • magnitude (Integer) (defaults to: 10)

    the magnitude of the shake

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to shake or :all to shake all layers

Since:

  • 2023-04-26



149
150
151
152
153
154
155
156
157
# File 'lib/or2d/animations/composite_animations.rb', line 149

def shake(target: :all, duration: 100, magnitude: 10)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].shake(duration: duration, magnitude: magnitude)
    end
  else
    OR2D.game.entities[@layers.keys[target]].shake(duration: duration, magnitude: magnitude)
  end
end

#shrink(factor: 1.0, delay: 100, target: :all) ⇒ Object

Shrink a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: 1.0)

    the factor by which to shrink

  • delay (Integer) (defaults to: 100)

    the delay before shrinking

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to shrink or :all to shrink all layers

Since:

  • 2023-04-26



106
107
108
109
110
111
112
113
114
# File 'lib/or2d/animations/composite_animations.rb', line 106

def shrink(factor: 1.0, delay: 100, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].shrink(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].shrink(factor: factor, delay: delay)
  end
end

#shrink_entity(factor: nil, delay: nil, target: nil) ⇒ Object

Shrinks the entity of a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: nil)

    the factor by which to shrink the entity

  • delay (Integer) (defaults to: nil)

    the delay before shrinking the entity

  • target (Symbol, Integer) (defaults to: nil)

    the index of the layer to shrink the entity or :all to shrink the entity of all layers

Since:

  • 2023-04-26



134
135
136
137
138
139
140
141
142
# File 'lib/or2d/animations/composite_animations.rb', line 134

def shrink_entity(factor: nil, delay: nil, target: nil)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].shrink_entity(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].shrink_entity(factor: factor, delay: delay)
  end
end

#shrink_text(factor: nil, delay: nil, target: :all) ⇒ Object

Shrink the text of a single layer of a Composite object, or all layers if no target is specified.

Parameters:

  • factor (Float) (defaults to: nil)

    the factor by which to shrink the text

  • delay (Integer) (defaults to: nil)

    the delay before shrinking the text

  • target (Symbol, Integer) (defaults to: :all)

    the index of the layer to shrink the text or :all to shrink the text of all layers

Since:

  • 2023-04-26



120
121
122
123
124
125
126
127
128
# File 'lib/or2d/animations/composite_animations.rb', line 120

def shrink_text(factor: nil, delay: nil, target: :all)
  if target == :all
    @layers.each_key do |layer|
      OR2D.game.entities[layer].shrink_text(factor: factor, delay: delay)
    end
  else
    OR2D.game.entities[@layers.keys[target]].shrink_text(factor: factor, delay: delay)
  end
end