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

Instance Method Summary collapse

Instance Attribute Details

#fade_rateObject

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_rateObject

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_rateObject

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



86
87
88
89
# File 'lib/chingu/traits/effect.rb', line 86

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



97
98
99
# File 'lib/chingu/traits/effect.rb', line 97

def fade_in(amount = 1)
  self.alpha += amount
end

#fade_out(amount = 1) ⇒ Object

Fade out objects color by decreasing color.alpha



92
93
94
# File 'lib/chingu/traits/effect.rb', line 92

def fade_out(amount = 1)
  self.alpha -= amount
end

#rotate(amount = 1) ⇒ Object

Rotate object 'amount' degrees



81
82
83
# File 'lib/chingu/traits/effect.rb', line 81

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.



67
68
69
70
# File 'lib/chingu/traits/effect.rb', line 67

def scale(amount = 0.1)
  self.factor_x += amount
  self.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.



74
75
76
77
# File 'lib/chingu/traits/effect.rb', line 74

def scale_out(amount = 0.1)
  self.factor_x -= amount
  self.factor_y -= amount
end

#setup_trait(options) ⇒ Object

Setup



49
50
51
52
53
54
55
56
57
# File 'lib/chingu/traits/effect.rb', line 49

def setup_trait(options)
  ## puts "Effect#setup_trait(#{options})"
  @rotation_rate = options[:rotation_rate] || nil
  @scale_rate = options[:scale_rate] || nil
  @scale_x_rate = options[:scale_x_rate] || nil
  @scale_y_rate = options[:scale_y_rate] || nil
  @fade_rate = options[:fade_rate] || nil
  super
end

#update_traitObject



59
60
61
62
63
64
# File 'lib/chingu/traits/effect.rb', line 59

def update_trait        
  rotate(@rotation_rate)  if @rotation_rate
  fade(@fade_rate)        if @fade_rate
  scale(@scale_rate)      if @scale_rate
  super
end