GSimpleParticleSystem class

A simple particle system that emits particles based on given parameters.

The particle system can be configured to emit particles in a variety of ways by setting parameters such as initial velocity, acceleration, angle, and color. The particle system can be set up to emit particles in a burst or continuously, and can be paused and resumed as needed.

The GSimpleParticleSystem can be rendered in world space or in local space.

The "variance" properties are used to add some randomization to certain particle properties. For example, the initialVelocityVariance property allows the initial velocity of each particle to vary randomly within a certain range around the initialVelocity value. This is what makes the particle system look more natural and less mechanical.

Example code:

   // create a circle texture to use for particles.
   final circ = await GTextureUtils.createCircle(
Inheritance
Available Extensions

Constructors

GSimpleParticleSystem()

Properties

$accumulatedEmission double
(Internal usage) The number of particles that have been emitted so far.
getter/setter pair
$accumulatedTime double
(Internal usage) The amount of time (in seconds) that has accumulated for the emitter.
getter/setter pair
$activeParticles int
(Internal usage) The number of active particles.
getter/setter pair
$alpha double
(Internal usage) The alpha (transparency) value of this object, a value between 0.0 (fully transparent) and 1.0 (fully opaque).
getter/setter pairinherited
$colorize Color?
(Internal usage) The color to apply to this object.
getter/setter pairinherited
$debugBounds bool
(Internal usage) Whether to show debug bounds for this object.
getter/setter pairinherited
$debugBoundsPaint Paint?
(Internal usage) Defines the debug paint used to show the bounds of this display object when debug mode is enabled. By default, it uses a magenta stroke with a width of 1. Override this property to use a custom debug paint.
getter/setter pairinherited
$debugLastLayerBounds GRect?
(Internal usage) Tracks the last layer bounds used for rendering this display object using getBounds($parent).
getter/setter pairinherited
$filters List<GBaseFilter>?
(Internal usage) The filters applied to this object.
getter/setter pairinherited
$firstParticle GSimpleParticle?
The first particle in the linked list of active particles.
getter/setter pair
$hasColorize bool
(Internal usage) Whether this object has a color applied to it.
no setterinherited
$hasTouchableArea bool
(Internal usage) Optimization flag indicating whether this object has a touchable area.
getter/setter pairinherited
$hasVisibleArea bool
(Internal usage) Optimization flag indicating whether this object has a visible area.
getter/setter pairinherited
$lastClickTime double
(Internal usage) The time of the last mouse click.
getter/setter pairinherited
$lastParticle GSimpleParticle?
The last particle in the linked list of active particles.
getter/setter pair
$lastUpdateTime double
(Internal usage) The last time (in seconds) that the emitter was updated.
getter/setter pair
$mask GShape?
(Internal usage) The mask of this object, used for masking.
getter/setter pairinherited
$maskee GDisplayObject?
(Internal usage) The display object that acts as a mask of this object.
getter/setter pairinherited
$matrixDirty bool
(Internal usage) Indicates whether the matrix of this object needs to be recalculated.
getter/setter pairinherited
$mouseDownObj GDisplayObject?
(Internal usage) The object that the mouse was last pressed on.
getter/setter pairinherited
$mouseOverObj GDisplayObject?
(Internal usage) The object that the mouse is currently over.
getter/setter pairinherited
$onAdded Signal?
(Internal)
getter/setter pairinherited
$onAddedToStage Signal?
(Internal)
getter/setter pairinherited
$onMouseClick EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseDoubleClick EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseDown EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseMove EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseOut EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseOver EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseUp EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onMouseWheel EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onPostPaint EventSignal<Canvas>?
(Internal)
getter/setter pairinherited
$onPrePaint EventSignal<Canvas>?
(Internal)
getter/setter pairinherited
$onPreTransform EventSignal<Canvas>?
(Internal)
getter/setter pairinherited
$onRemoved Signal?
(Internal)
getter/setter pairinherited
$onRemovedFromStage Signal?
(Internal)
getter/setter pairinherited
$onRightMouseDown EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$onZoomPan EventSignal<MouseInputData>?
(Internal)
getter/setter pairinherited
$parent GDisplayObjectContainer?
(Internal usage) The parent display object container that this object is a child of.
getter/setter pairinherited
$useSaveLayerBounds bool
(Internal usage) When enabled, a rectangle is created to save the layer for better rendering performance.
getter/setter pairinherited
allowSaveLayer bool
When enabled, the saveLayer() feature is used for better rendering performance. Disabling it may provide better performance for certain display objects. Childless DisplayObjects, like GShape and GBitmap, have their own Paint() so no need to use an expensive saveLayer().
getter/setter pairinherited
alpha double
Returns the alpha (transparency) value of this object.
getter/setter pairinherited
base GDisplayObject
Returns the base object, i.e. the topmost parent in the display hierarchy.
no setterinherited
blendMode BlendMode
The current blend mode applied to the particle system.
getter/setter pair
bounds GRect?
TODO: should be cached. Returns the bounds of this object in its local coordinate space.
no setterinherited
burst bool
Whether to emit all particles in a burst.
getter/setter pair
colorize Color?
Gets the color applied to this object.
getter/setter pairinherited
dispersionAngle double
The angle in radians of the emission arc.
getter/setter pair
dispersionAngleVariance double
The variance of the angle in radians for the emission arc.
getter/setter pair
dispersionXVariance double
The amount of random horizontal movement for each particle.
getter/setter pair
dispersionYVariance double
The amount of random vertical movement for each particle.
getter/setter pair
drawCallback ↔ (void Function(Canvas?, Paint)?)
Optional draw callback function to be executed before drawing the particles.
getter/setter pair
emission int
The number of particles to emit per emissionTime.
getter/setter pair
emissionDelay double
The amount of seconds to delay before starting the emission.
getter/setter pair
emissionTime double
The amount of seconds to emit emission particles, works next to emissionDelay... So if you wanna emit for 1 second, and stop for 1 second, and emit for 1 second again, you can set emissionTime to 1, and emissionDelay to 1.
getter/setter pair
emissionVariance int
The variance of (how random) the number of particles to emit during emissionTime.
getter/setter pair
emit bool
Whether to emit particles or not. starts "on" by default. When you set burst to true or call forceBurst, you have to manually set this to true again.
getter/setter pair
endAlpha double
The end alpha value of the particles.
getter/setter pair
endAlphaVariance double
The variance in the end alpha value of the particles.
getter/setter pair
endBlue double
The end blue value of the particles.
getter/setter pair
endBlueVariance double
The variance in the end blue value of the particles.
getter/setter pair
endColor int
Gets the endColor as a hex value. The endRed, endGreen, and endBlue values are converted to hex from [0, 255] range and combined to create the hex color with format 0xRRGGBB.
getter/setter pair
endGreen double
The end green value of the particles.
getter/setter pair
endGreenVariance double
The variance in the end green value of the particles.
getter/setter pair
endRed double
The end red value of the particles.
getter/setter pair
endRedVariance double
The variance in the end red value of the particles.
getter/setter pair
endScale double
The end scale of the particles.
getter/setter pair
endScaleVariance double
The variance in end scale of the particles.
getter/setter pair
energy double
The energy of the particles in seconds (how much it will live).
getter/setter pair
energyVariance double
The variance of the energy of the particles emitted.
getter/setter pair
filterPaint Paint
The paint to use for filters that require a paint.
getter/setter pairinherited
filters List<GBaseFilter>?
Gets the filters applied to this object.
getter/setter pairinherited
hasFilters bool
Returns true if this object has any filters applied.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
height double
Indicates the height of the display object, in dp. The height is calculated based on the bounds of the content of the display object. When you set the height property, the scaleX property is adjusted accordingly, as shown in the following code:
getter/setter pairinherited
initialAcceleration double
The initial acceleration of the particles emitted.
getter/setter pair
initialAccelerationVariance double
The variance of the initial acceleration of the particles emitted.
getter/setter pair
initialAlpha double
TODO: Maybe use a single Color instead? The initial alpha value of the particles.
getter/setter pair
initialAlphaVariance double
The variance in the initial alpha value of the particles.
getter/setter pair
initialAngle double
The initial angle of the particles emitted.
getter/setter pair
initialAngleVariance double
The variance of the initial angle of the particles emitted.
getter/setter pair
initialAngularVelocity double
The initial angular velocity of the particles emitted.
getter/setter pair
initialAngularVelocityVariance double
The variance of the initial angular velocity of the particles emitted.
getter/setter pair
initialBlue double
The initial blue value of the particles.
getter/setter pair
initialBlueVariance double
The variance in the initial blue value of the particles.
getter/setter pair
initialColor int
The initial color of the particle, represented as a 32-bit integer. The alpha channel is ignored. The default value is 0xffffff.
getter/setter pair
initialGreen double
The initial green value of the particles.
getter/setter pair
initialGreenVariance double
The variance in the initial green value of the particles.
getter/setter pair
initialRed double
The initial red value of the particles.
getter/setter pair
initialRedVariance double
The variance in the initial red value of the particles.
getter/setter pair
initialScale double
---- PROPERTIES --- The initial scale of the particles.
getter/setter pair
initialScaleVariance double
The variance in initial scale of the particles.
getter/setter pair
initialVelocity double
The initial velocity of the particles emitted.
getter/setter pair
initialVelocityVariance double
The variance of the initial velocity of the particles emitted.
getter/setter pair
inStage bool
Returns true if this object is on the stage.
no setterinherited
isMask bool
Returns whether this object is currently being used as a mask for another object.
no setterinherited
isRotated bool
Returns whether this object has any rotation or skew transformation.
no setterinherited
mask GShape?
Returns the mask of this object.
getter/setter pairinherited
maskInverted bool
Whether the object should apply an inverted mask. can be set on the Shape mask, or the maskee DisplayObject.
getter/setter pairinherited
maskRect GRect?
The rectangular area of the mask.
getter/setter pairinherited
maskRectCornerRadius double?
The corner radius of the mask.
getter/setter pairinherited
maskRectInverted bool
Whether the mask is inverted or not.
getter/setter pairinherited
mouseEnabled bool
Indicates whether this object can receive mouse and touch input events.
getter/setter pairinherited
mousePosition GPoint
Returns the position of the mouse in the local coordinate system of this object. The mouse position is updated every frame, so this method returns the current mouse position relative to the top-left corner of this object.
no setterinherited
mouseUseShape bool
Whether to use the shape of the object for mouse event detection.
getter/setter pairinherited
mouseX double
The x-coordinate of the mouse or touch position in the local coordinate system of this object.
no setterinherited
mouseY double
The y-coordinate of the mouse or touch position in the local coordinate system of this object.
no setterinherited
name String?
Name to reference this object.
getter/setter pairinherited
nativePaint Paint
Native Paint instance used to draw the particles.
final
onAdded Signal
Returns the Signal that is triggered when an object is added to the display list.
no setterinherited
onAddedToStage Signal
Returns the Signal that is triggered when an object is added to the stage.
no setterinherited
onMouseClick EventSignal<MouseInputData>
A signal that is dispatched when the mouse is clicked.
no setterinherited
onMouseDoubleClick EventSignal<MouseInputData>
A signal that is dispatched when the mouse is double clicked.
no setterinherited
onMouseDown EventSignal<MouseInputData>
A signal that is dispatched when the mouse button is pressed down.
no setterinherited
onMouseMove EventSignal<MouseInputData>
A signal that is dispatched when the mouse is moved.
no setterinherited
onMouseOut EventSignal<MouseInputData>
A signal that is dispatched when the mouse leaves a component.
no setterinherited
onMouseOver EventSignal<MouseInputData>
A signal that is dispatched when the mouse is over a component.
no setterinherited
onMouseScroll EventSignal<MouseInputData>
A signal that is dispatched when the mouse wheel is scrolled.
no setterinherited
onMouseUp EventSignal<MouseInputData>
A signal that is dispatched when the mouse button is released.
no setterinherited
onPostPaint EventSignal<Canvas>
A signal that runs right after GDisplayObject.$applyPaint is called.
no setterinherited
onPrePaint EventSignal<Canvas>
A signal that runs before GDisplayObject.$applyPaint, which is the render method to subclass.
no setterinherited
onPreTransform EventSignal<Canvas>
A signal that runs right away when GDisplayObject.paint is called, before any mask or filters are applied. This is the first signal to run on rendering.
no setterinherited
onRemoved Signal
Returns the Signal that is triggered when an object is removed from the display list.
no setterinherited
onRemovedFromStage Signal
Returns the Signal that is triggered when an object is removed from the stage.
no setterinherited
onRightMouseDown EventSignal<MouseInputData>
A signal that is dispatched when the right mouse button is pressed down.
no setterinherited
onZoomPan EventSignal<MouseInputData>
A signal that is dispatched when a zoom/pan gesture is performed.
no setterinherited
parent GDisplayObjectContainer?
Returns the parent container.
no setterinherited
particleBlendMode BlendMode
The blend mode to use for particles.
getter/setter pair
particlePivotX double?
The x-coordinate of the particle pivot point relative to the particle's origin.
getter/setter pair
particlePivotY double?
The y-coordinate of the particle pivot point relative to the particle's origin.
getter/setter pair
paused bool
Whether the particle system is paused or not.
getter/setter pair
pivotX double
Returns the x coordinate of the pivot point, the center of scaling and rotation.
getter/setter pairinherited
pivotY double
Returns the y coordinate of the pivot point, the center of scaling and rotation.
getter/setter pairinherited
root GDisplayObject?
Returns the root GDisplayObject that is the ancestor of this object (either a Stage or a null).
no setterinherited
rotation double
Returns the angle of rotation in radians.
getter/setter pairinherited
rotationX double
The rotation angle in radians about the x-axis for 3d transformation.
getter/setter pairinherited
rotationY double
The rotation angle in radians about the y-axis for 3d transformation.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale double
Shortcut for setting proportional X and Y scale values.
getter/setter pairinherited
scaleX double
Returns the horizontal scale of the object.
getter/setter pairinherited
scaleY double
Returns the vertical scale of the object.
getter/setter pairinherited
skewX double
Returns the angle of skew on the x-axis in radians.
getter/setter pairinherited
skewY double
Returns the angle of skew on the y-axis in radians.
getter/setter pairinherited
stage Stage?
Returns the stage this object is on or null if it's not on a stage.
no setterinherited
texture GTexture?
The image texture used for each particle.
getter/setter pair
transformationMatrix GMatrix
Gets the transformation matrix that represents the object's position, scale, rotation and skew.
getter/setter pairinherited
useAlphaOnColorFilter bool
If set to true, ColorFilter alpha will be used to draw the particles.
getter/setter pair
useCursor bool
Whether to use a custom cursor for this object.
getter/setter pairinherited
userData Object?
You can store any user defined data in this property for easy access.
getter/setter pairinherited
useWorldSpace bool
Whether to use world space for particle rendering.
getter/setter pair
visible bool
Returns whether the display object is visible or not.
getter/setter pairinherited
width double
Indicates the width of the display object, in dp. The width is calculated based on the bounds of the content of the display object. When you set the width property, the scaleX property is adjusted accordingly, as shown in the following code:
getter/setter pairinherited
worldAlpha double
Returns the alpha value of the object relative to its parent and all its ancestors.
no setterinherited
worldScaleX double
Returns the horizontal scaling factor of the object relative to its parent and all its ancestors.
no setterinherited
worldScaleY double
Returns the vertical scaling factor of the object relative to its parent and all its ancestors.
no setterinherited
worldX double
Returns the x coordinate of the object relative to the stage and all its ancestors.
no setterinherited
worldY double
Returns the y coordinate of the object relative to the stage and all its ancestors.
no setterinherited
x double
The x coordinate of the display object relative to its parent's coordinate system.
getter/setter pairinherited
y double
The y coordinate of the display object relative to its parent's coordinate system.
getter/setter pairinherited
z double
(Experimental) The z-coordinate of this object in 3D space.
getter/setter pairinherited

Methods

$applyMaskRect(Canvas? canvas) → void
Applies the current mask to the provided Canvas.
inherited
$applyPaint(Canvas? canvas) → void
(Internal usage) Renders the particle system onto the given Canvas.
override
$deactivateParticle(GSimpleParticle particle) → void
Deactivates the given particle and removes it from the linked list of particles.
$dispatchMouseCallback(MouseInputType type, GDisplayObject object, MouseInputData input) → void
(Internal usage) Dispatches a mouse event to the appropriate callback functions.
inherited
$disposeDisplayListSignals() → void
Removes all registered listeners and frees all display list signals.
inherited
$disposePointerSignals() → void
Disposes all mouse signals to free up memory.
inherited
$disposeRenderSignals() → void
Disposes all render-related signals and clears all callbacks for this instance. This method should be called when the instance is no longer needed, to prevent memory leaks.
inherited
$setParent(GDisplayObjectContainer? value) → void
(Internal usage) Sets the GDisplayObjectContainer that contains this GDisplayObject.
inherited
$setTransformationChanged() → void
(Internal usage) Sets the transformationChanged flag and updates the 3D flag based on whether the object has 3D properties set.
inherited
$updateTransformationMatrices(double? x, double? y, double pivotX, double pivotY, double scaleX, double scaleY, double skewX, double skewY, double rotation, GMatrix out) → void
(Internal usage) Updates the transformation matrices of a display object based on the given parameters.
inherited
activateParticle() → void
Creates and activates a new particle.
addedToStage() → void
Called when the object is added to the stage. Should be overridden by subclasses as entry point.
inherited
alignPivot([Alignment alignment = painting.Alignment.center]) → void
Adjusts the pivot point of this display object to a new location defined by the given alignment parameter, which defaults to Alignment.center. This method calculates the bounds of the object and aligns the pivot point based on the provided alignment parameter. The alignment is represented by an Alignment object, where the x and y values range from -1.0 to 1.0. For example, an Alignment of (-1.0, -1.0) represents the top left corner, while an Alignment of (1.0, 1.0) represents the bottom right corner. The pivot point represents the center point for rotations and scaling, and by default it is set to (0,0), which means that the object is rotated and scaled around the top-left corner. This method is useful to adjust the pivot point to a more suitable location before performing rotations or scaling operations. If the bounds of the object are empty, no adjustment is made to the pivot point. The resulting pivot point is stored in the pivotX and pivotY properties of this display object.
inherited
captureMouseInput(MouseInputData input) → void
Captures mouse input and dispatches corresponding mouse events to this display object if it has a touchable area and mouseEnabled is set to true.
inherited
clear() → void
Clears all particles from the system.
createImage([bool adjustOffset = true, double resolution = 1, GRect? rect]) Future<Image>
Creates an image representation of the current state of the GDisplayObject. If adjustOffset is true, the resulting image will be offset so that its top-left corner corresponds to the top-left corner of the current bounds. If resolution is provided and is different than 1, the image will be scaled by this factor before being returned. If rect is provided, it defines a rectangle that will be used as the bounds for the image instead of the getFilterBounds of the GDisplayObject. Returns a Future that resolves to a ui.Image representing the current state of the GDisplayObject in the form of an image.
inherited
createImageSync([bool adjustOffset = true, double resolution = 1, GRect? rect]) Image
Creates a synchronous image from this display object.
inherited
createImageTexture([bool adjustOffset = true, double resolution = 1, GRect? rect]) Future<GTexture>
Creates a new GTexture asynchronously from the display object's image. The image is retrieved using the createImage method, and a new texture is created from the image with the specified resolution. If a rect is specified, only the portion of the image within the bounds of the rectangle will be used to create the texture. If adjustOffset is true, the image will be adjusted to remove any offsets from the top left corner.
inherited
createImageTextureSync([bool adjustOffset = true, double resolution = 1, GRect? rect]) GTexture
Creates a texture from the synchronous image generated from this display object.
inherited
createPicture([void prePaintCallback(Canvas)?, void postPaintCallback(Canvas)?]) Picture
Creates a picture of the current state of the DisplayObject. To ensure the "original" form, call before applying any transformations (x, y, scale, etc).
inherited
dispose() → void
Disposes all particles and removes the onUpdate callback.
override
forceBurst() → void
Emits particles immediately by creating emission particles and activating them. The emit flag is set to false after the burst, so remember to set it back to true if you want the particle system to continue emitting particles.
getBounds(GDisplayObject? targetSpace, [GRect? out]) GRect
Returns the bounds of the particle system in a given target space.
override
getFilterBounds([GRect? layerBounds, Paint? alphaPaint]) GRect?
Returns the bounds of this object after applying all its filters.
inherited
getTransformationMatrix(GDisplayObject? targetSpace, [GMatrix? out]) GMatrix
Returns the transformation matrix that transforms coordinates from the local coordinate system to the coordinate system of the targetSpace.
inherited
globalToLocal(GPoint globalPoint, [GPoint? out]) GPoint
Converts the given point from global coordinates to local coordinates.
inherited
hasLivingParticles() bool
Returns true if there are living particles in the linked list.
hitTest(GPoint localPoint, [bool useShape = false]) GDisplayObject?
Determines if this object overlaps with the given localPoint.
inherited
hitTestMask(GPoint localPoint) bool
Determines whether the localPoint specified in the local coordinates of this object lies inside its mask.
inherited
hitTouch(GPoint localPoint, [bool useShape = false]) bool
Determines whether the localPoint specified in the local coordinates of this object lies inside its bounds.
inherited
localToGlobal(GPoint localPoint, [GPoint? out]) GPoint
Transforms the given localPoint from the local coordinate system to the global coordinate system.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paint(Canvas canvas) → void
Called by GraphX rendering on each frame to render the particle system.
override
removedFromStage() → void
Called when the object is removed to the stage.
inherited
removeFromParent([bool dispose = false]) → void
Removes this GDisplayObject from its parent GDisplayObjectContainer.
inherited
requiresRedraw() → void
Notifies the parent that the current state of this GDisplayObject has changed and it requires a redraw.
inherited
setPosition(double x, double y) GDisplayObject
Sets the x and y transformation of the DisplayObject and returns it.
inherited
setScale(double scaleX, [double? scaleY]) GDisplayObject
Sets the scaleX and scaleY transformation of the DisplayObject and returns it. If only one argument is provided, both scaleX and scaleY are set to the same value.
inherited
setup([int maxCount = 0, int precacheCount = 0, bool disposeImmediately = true]) → void
Sets up the particle system to start fresh.
startDrag([bool lockCenter = false, GRect? bounds]) → void
Makes this object draggable. When this object is dragged, its x and y properties will be updated to match the mouse position. The lockCenter parameter, if set to true, will cause the object to be dragged from its center point. The bounds parameter can be used to restrict the movement of the object to a certain area. Throws an error if the object is not visible or touchable.
inherited
stopDrag() → void
Stops the current drag operation, if this DisplayObject is currently being dragged. Removes the mouse move event listener and sets the current drag object to null. Does nothing if this DisplayObject is not currently being dragged.
inherited
toString() String
Returns a string representation of this object.
inherited
update(double delta) → void
(Internal usage) Called by GraphX on each frame to update the particle system.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited