Module: Chingu::Traits::Effect
- Defined in:
- lib/chingu/traits/effect.rb
Overview
Adds methods:
rotate(amount) # modifies @angle
scale(amount) # modifies @factor_x and @factor_y
fade(amount) # modifies @color.alpha
Also adds attributes
rotation_rate = amount # adds amount to @angle each game loop
scale_rate = amount # adds amount to @factor_x and @factor_y each game loop
fade_rate = amount # adds amount to @color.alpha each game loop
WARNING, I’m very close to deprecating this trait, it doesn’t do much and still introduces new names to learn. After a long discussion in #gosu I feel it’s just better to use the accessors angle=, alpha= and factor=
BasicGameObject#alpha= contains the most important logic this trait had now anyhow.
Instance Attribute Summary collapse
-
#fade_rate ⇒ Object
Returns the value of attribute fade_rate.
-
#rotation_rate ⇒ Object
Returns the value of attribute rotation_rate.
-
#scale_rate ⇒ Object
Returns the value of attribute scale_rate.
Instance Method Summary collapse
-
#fade(amount = 1) ⇒ Object
Fade object by decreasing/increasing color.alpha.
-
#fade_in(amount = 1) ⇒ Object
Fade in objects color by increasing color.alpha.
-
#fade_out(amount = 1) ⇒ Object
Fade out objects color by decreasing color.alpha.
-
#rotate(amount = 1) ⇒ Object
Rotate object ‘amount’ degrees.
-
#scale(amount = 0.1) ⇒ Object
(also: #zoom)
Increase @factor_x and @factor_y at the same time.
-
#scale_out(amount = 0.1) ⇒ Object
(also: #zoom_out)
Ddecrease @factor_x and @factor_y at the same time.
-
#setup_trait(options) ⇒ Object
Setup.
- #update_trait ⇒ Object
Instance Attribute Details
#fade_rate ⇒ Object
Returns the value of attribute fade_rate.
44 45 46 |
# File 'lib/chingu/traits/effect.rb', line 44 def fade_rate @fade_rate end |
#rotation_rate ⇒ Object
Returns the value of attribute rotation_rate.
44 45 46 |
# File 'lib/chingu/traits/effect.rb', line 44 def rotation_rate @rotation_rate end |
#scale_rate ⇒ Object
Returns the value of attribute scale_rate.
44 45 46 |
# File 'lib/chingu/traits/effect.rb', line 44 def scale_rate @scale_rate end |
Instance Method Details
#fade(amount = 1) ⇒ Object
Fade object by decreasing/increasing color.alpha
84 85 86 87 |
# File 'lib/chingu/traits/effect.rb', line 84 def fade(amount = 1) return if amount == 0 self.alpha += amount end |
#fade_in(amount = 1) ⇒ Object
Fade in objects color by increasing color.alpha
95 96 97 |
# File 'lib/chingu/traits/effect.rb', line 95 def fade_in(amount = 1) self.alpha += amount end |
#fade_out(amount = 1) ⇒ Object
Fade out objects color by decreasing color.alpha
90 91 92 |
# File 'lib/chingu/traits/effect.rb', line 90 def fade_out(amount = 1) self.alpha -= amount end |
#rotate(amount = 1) ⇒ Object
Rotate object ‘amount’ degrees
79 80 81 |
# File 'lib/chingu/traits/effect.rb', line 79 def rotate(amount = 1) self.angle += amount end |
#scale(amount = 0.1) ⇒ Object Also known as: zoom
Increase @factor_x and @factor_y at the same time.
65 66 67 68 |
# File 'lib/chingu/traits/effect.rb', line 65 def scale(amount = 0.1) @factor_x += amount @factor_y += amount end |
#scale_out(amount = 0.1) ⇒ Object Also known as: zoom_out
Ddecrease @factor_x and @factor_y at the same time.
72 73 74 75 |
# File 'lib/chingu/traits/effect.rb', line 72 def scale_out(amount = 0.1) @factor_x -= amount @factor_y -= amount end |
#setup_trait(options) ⇒ Object
Setup
49 50 51 52 53 54 55 |
# File 'lib/chingu/traits/effect.rb', line 49 def setup_trait() ## puts "Effect#setup_trait(#{options})" @rotation_rate = [:rotation_rate] || nil @scale_rate = [:scale_rate] || nil @fade_rate = [:fade_rate] || nil super end |
#update_trait ⇒ Object
57 58 59 60 61 62 |
# File 'lib/chingu/traits/effect.rb', line 57 def update_trait rotate(@rotation_rate) if @rotation_rate fade(@fade_rate) if @fade_rate scale(@scale_rate) if @scale_rate super end |