Particles2d module i'm working on

This is the first module I’m working on using OOP, mostly to practice using OOP, but I will also probably release it to everyone if there is interest. This isn’t in #resources:community-resources yet because I feel like I need some feedback on it first. Feel free to leave any comments suggesting different things to add or change!

Documentation
Particles2d:Create()

Creates a new Particles2d emitter with the specified parameters. Any non-required parameter left nil will result in its default value

Parameters:

GUIobject - A gui Instance (frame, imagelabel, textlabel, etc) that is what will be cloned by the module to create the particles. THIS PARAMETER IS REQUIRED

EmitPosition - A UDim2 or table value to determine where the particles will start from. If you use a table value, the table must have two UDim2 values named TopLeft and BottomRight (ex: {TopLeft = UDim2.new(.4,0,.1,0), BottomRight = UDim2.new(.6,0,.9,0)}, and the particles will spawn anywhere in that area (Kind of like a Region3 but for 2d) THIS PARAMETER IS REQUIRED

Speed - A number or NumberRange value to determine how fast the particles will move on the Y axis, can be negative or positive

xVelocity - A number or NumberRange value to determine how fast the particles will move on the X axis, can be negative or positive

RotationSpeed - A number or NumberRange value to determine how fast the particles will spin, can be negative or positive

Lifetime - A number or NumberRange value to determine how long the particles last in seconds, can only be positive or an error will occur

Gravity - A number value to determine how much downwards force is being applied on the particles, can be negative or positive

TweenProperties - A table value that contains all the properties to tween over the lifetime of the particle. It is the exact same thing that you would put as the last parameter in TweenService:Create()

TimeScale - A number value that scales how fast or slow the particles will go through their lifetime, 1 is normal, <1 is slower, and >1 is faster, can only be positive or error will occur

Particles2d:Emit()

Emits new particles from an existing Particles2d emitter

Parameters:

Amount - A number value that determines how many particles will be emitted, can only be positive or an error will occur THIS PARAMETER IS REQUIRED

Particles2d:Clear()

Clears all the existing particles of a Particles2d emitter

Parameters:

DelayTime - A number value that determines how long in seconds the function will wait before clearing the particles of a particle emitter (Does not yield the thread that calls the function)

Sample Code

This code will create a confetti-like particle emitter with any gui object. (I am using a small frame with a red background color)

local Particles2d = require(game.ReplicatedStorage.Particles2d)

local GUIobject = script.Parent.Frame
local EmitPosition = UDim2.fromScale(.5,1.2)
local Speed = NumberRange.new(100,125)
local xVelocity = NumberRange.new(-30,30)
local RotationSpeed = NumberRange.new(-20,20)
local Lifetime = NumberRange.new(1.5,2)
local Gravity = 12
local TweenProperties = {Size = UDim2.fromOffset(0,0), BackgroundColor3 = Color3.new(1,0,0)}
local TimeScale = 1.5

local particleEmitter = Particles2d:Create(GUIobject, EmitPosition, Speed, xVelocity, RotationSpeed, Lifetime, Gravity, TweenProperties, TimeScale)

while task.wait(3) do
   for i = 1,5 do
       particleEmitter:Emit(10)
       task.wait(.1)
   end
end

Here is the result:

Model: Particles2d - Roblox

5 Likes