Method: MiniGL::Particles::Particle#initialize
- Defined in:
- lib/minigl/particles.rb
#initialize(x:, y:, duration:, shape: nil, img: nil, **options) ⇒ Particle
Returns a new instance of Particle.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/minigl/particles.rb', line 212 def initialize(x:, y:, duration:, shape: nil, img: nil, **) @x = x @y = y @duration = duration @shape = shape @img = img @options = DEFAULT_OPTIONS.slice(*PARTICLE_OPTIONS).merge() @elapsed_time = 0 if @options[:angle].is_a?(Range) @angle = rand(@options[:angle]) elsif @options[:angle].is_a?(Numeric) @angle = @options[:angle] end if @options[:speed].is_a?(Hash) speed_x = @options[:speed][:x].is_a?(Range) ? rand(@options[:speed][:x]) : (@options[:speed][:x] || 0) speed_y = @options[:speed][:y].is_a?(Range) ? rand(@options[:speed][:y]) : (@options[:speed][:y] || 0) @speed = Vector.new(speed_x, speed_y) elsif @options[:speed].is_a?(Vector) @speed = @options[:speed] end init_variable_property(:scale) init_variable_property(:alpha) end |