Class: ParticleFX2D::Ruby2D::ParticleImage

Inherits:
Ruby2D::Image
  • Object
show all
Includes:
ShapeRenderer
Defined in:
lib/particlefx2d/ruby2d/particle_image.rb

Overview

A particle shape that is based on the Ruby2D Image.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShapeRenderer

#hide_particle, #show_particle

Methods included from ParticleFX2D::Renderer

#hide_particle, #show_particle

Class Method Details

.for(particle) ⇒ Object

Called by the emitter for each particle that it manages. Creates an instance of ParticleImage using #image_path to obtain the file to load as image and intialized with the particle’s position, size and colour.

Parameters:



23
24
25
26
27
# File 'lib/particlefx2d/ruby2d/particle_image.rb', line 23

def self.for(particle)
  s = ParticleImage.new image_path, width: particle.size, height: particle.size
  s.remove
  s
end

.image_pathObject

This class method is used to identify the image file to load. Create a subclass and override this method to define your own particle shapes based on image files.



13
14
15
# File 'lib/particlefx2d/ruby2d/particle_image.rb', line 13

def self.image_path
  "#{File.dirname(__FILE__)}/../images/particle.png"
end

Instance Method Details

#center!(centre_x, centre_y) ⇒ Object

Sets the images’s position using the incoming centre coordinates offset by the shape’s mid-size.



31
32
33
34
# File 'lib/particlefx2d/ruby2d/particle_image.rb', line 31

def center!(centre_x, centre_y)
  self.x = centre_x - (width / 2)
  self.y = centre_y - (height / 2)
end

#draw_particle(particle) ⇒ Object

Sets the image size using the particle size and calls #super



37
38
39
40
# File 'lib/particlefx2d/ruby2d/particle_image.rb', line 37

def draw_particle(particle)
  self.width = self.height = particle.size
  super
end