Sha256: d885c6c05198b7c6b395448d6ed79bf022a70d66d81c2e6d49f2fce6af5db37a
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module ParticleFX2D module Ruby2D # # A particle shape that is based on the Ruby2D _Image_. class ParticleImage < ::Ruby2D::Image include ShapeRenderer # 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. def self.image_path "#{File.dirname(__FILE__)}/../images/particle.png" end # 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. # # @param [ParticleFX2D::Particle] particle # def self.for(particle) s = ParticleImage.new image_path, width: particle.size, height: particle.size s.remove s end # Sets the images's position using the incoming centre coordinates # offset by the shape's mid-size. def center!(centre_x, centre_y) self.x = centre_x - (width / 2) self.y = centre_y - (height / 2) end # Sets the image size using the particle size and calls #super def draw_particle(particle) self.width = self.height = particle.size super end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
particlefx2d-0.5.0 | lib/particlefx2d/ruby2d/particle_image.rb |