Skip to content

Particle

KabanFriends edited this page Dec 9, 2022 · 9 revisions

Particles are objects used to register custom particles. You can get a new particle object by calling particle.new(). Upon creating a new particle object, you can edit the following properties before registering the particle.

x : number

  • The X coordinate of the top-left point in the particles.png texture.
  • Assuming particles.png is 256x256 pixels, this value responds to the actual pixel coordinates.

y : number

  • The Y coordinate of the top-left point in the particles.png texture.
  • Assuming particles.png is 256x256 pixels, this value responds to the actual pixel coordinates.

width : number

  • The texture width of this particle.
  • Assuming particles.png is 256x256 pixels, this value responds to the actual pixel coordinates.

height : number

  • The texture height of this particle.
  • Assuming particles.png is 256x256 pixels, this value responds to the actual pixel coordinates.

tintRed : number

  • Red component of the RGB color to tint the particle texture.
  • The value must be between 0 and 255.

tintBlue : number

  • Blue component of the RGB color to tint the particle texture.
  • The value must be between 0 and 255.

tintGreen : number

  • Green component of the RGB color to tint the particle texture.
  • The value must be between 0 and 255.

frameCount : number

  • Determines how many frames of animation will be played over the particle's lifespan (faster life, faster animation).
  • Frames are always the same size as each other and are stored left-to-right in particles.png.

particleCount : number

  • How many particles are spawned every time you use player.playParticle( ... ).

size : number

  • How large in "pixel" units the particle is. 8 is the size of a player's head. You are allowed to be as precise as half a pixel, therefore the smallest possible size is 0.5.

sizeVariation : number

  • How much the particle can randomly vary in size. 1 means 100% variation and 0 means 0% variation.

spread : number

  • Allows the particles to spawn randomly around the point they were told to spawn at.
  • A spread of "0.5" is equal to the width of a full block (because the spread goes both ways).

speed : number

  • How fast this particles moves away from the origin.

gravity : number

  • Gravity value adds to the up/down speed of the particle over time.
  • For example, -1 means that the particle will float up.

lifetime : number

  • Time in seconds this particle is allowed to live at most.
  • Depending on the collision options below, particles might disappear sooner than specified in this field.

lifetimeVariation : number

  • How much the particle's lifespan can randomly vary. 1 means 100% variation, 0 means 0% variation.

fullBright : boolean

  • If true, the particle will always have its original brightness, even in dark environments.

expireUponTouchingGround : boolean

  • If true, the particle disappears if it hits a solid floor (What counts as "solid" are determined in the fields listed below)

collideSolid : boolean

collideLiquid : boolean

collideLeaves : boolean

Registering Particles

Particles can be registered and unregistered using following functions. particle is a constant variable that can be accessed from anywhere.

particle.new()

  • Returns a new instance of particle table. See above for the properties you can edit.

particle.register(string: name, table: particle)

  • Registers a particle table that was created using particle.new(), with the given name. You can register up to 256 particles.
  • Note that this will send the particle data to all players in the level, which might cause lags when used on loop.

particle.unregister(string: name)

  • Unregisters a particle by its name, and frees up the internal space taken by that particle.

Example

local par = particle.new()
	
par.x = 0
par.y = 0
par.width = 10
par.height = 10

par.tintRed = 255
par.tintGreen = 163
par.tintBlue = 190

par.frameCount = 8
par.particleCount = 1

par.size = 8
par.sizeVariation = 0.5

par.spread = 0.5
par.speed = 0.25
par.gravity = -1

par.lifetime = 0.5
par.lifetimeVariation = 0

par.expireUponTouchingGround = false
par.collideSolid = false
par.collideLiquid = false
par.collideLeaves = false

par.fullBright = true

particle.register("heart", par)
player.playParticle("heart", player.x, player.y, player.z) -- Plays the registered particle effect
Clone this wiki locally