Class Particle
- All Implemented Interfaces:
ITimeToLive
- Direct Known Subclasses:
ShapeParticle, SpriteParticle, TextParticle
Base class for particles spawned by a Emitter. A particle has a position, velocity, acceleration, lifetime, color and rendering options.
Subclasses are responsible for implementing [Point2D)][#render(Graphics2D,] which draws the particle relative to the emitter origin.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedParticle(float width, float height) Constructs a new particle. -
Method Summary
Modifier and TypeMethodDescriptiongetAbsoluteLocation(Point2D effectLocation) Computes the absolute world location of this particle given an emitter origin.protected floatgetAbsoluteX(Point2D emitterOrigin) Computes the absolute world X coordinate of this particle, accounting for the particle's width.protected floatgetAbsoluteY(Point2D emitterOrigin) Computes the absolute world Y coordinate of this particle, accounting for the particle's height.floatGets the horizontal acceleration of the particle.floatGets the vertical acceleration of the particle.longGets the time this instance is alive.floatgetAngle()Gets the current rotation angle of the particle, in degrees.getBoundingBox(Point2D origin) Gets the current bounding box of the particle, depending on its spawn location.Gets the collision behavior of this particle.getColor()Gets the current color of the particle.Gets the custom render type that overrides the emitter's render type, ifusesCustomRenderType()istrue.floatGets the per-update angle delta applied to the particle, in degrees.floatGets the per-update height delta applied to the particle.floatGets the per-update width delta applied to the particle.floatGets the current height of the particle, in pixels.floatComputes the current opacity of the particle.floatGets the outline thickness used when rendering the particle as an outline.getRenderLocation(Point2D effectLocation) Gets the location relative to the specified effect location.intGets the total time to live of this instance.floatGets the horizontal velocity of the particle.floatGets the vertical velocity of the particle.floatgetWidth()Gets the current width of the particle, in pixels.floatgetX()Gets the X position of the particle relative to its emitter origin.floatgetY()Gets the Y position of the particle relative to its emitter origin.protected booleanhasRayCastCollision(Point2D emitterOrigin, float updateRatio) Test for ray cast collisionsinit(EmitterAttributes data) Initializes this particle's mutable state from the suppliedEmitterAttributes.booleanReturns whether the particle is rendered with anti-aliasing.booleanReturns whether continuous (ray-cast) collision detection is enabled for this particle.booleanisFading()Returns whether the particle fades out over its lifetime.booleanReturns whether the particle fades upon collision.booleanReturns whether the particle is rendered as an outline only.booleanReturns whether the particle stops moving once a collision occurs.abstract voidrender(Graphics2D g, Point2D emitterOrigin) Renders this particle to the given graphics context.setAccelerationX(float accelerationX) Sets the horizontal acceleration of the particle.setAccelerationY(float accelerationY) Sets the vertical acceleration of the particle.setAngle(float angle) Sets the current rotation angle of the particle, in degrees.setAntiAliasing(boolean antiAliasing) Sets whether the particle is rendered with anti-aliasing.setCollisionType(Collision collisionType) Sets the collision behavior of this particle.Sets the color of the particle.setContinuousCollision(boolean ccd) Enabling this check can be very performance hungry and should be used with caution and only for a small amount of particles.setCustomRenderType(RenderType renderType) Sets a custom render type that overrides the emitter's render type for this particle.setDeltaAngle(float deltaAngle) Sets the per-update angle delta applied to the particle, in degrees.setDeltaHeight(float deltaHeight) Sets the per-update height delta applied to the particle.setDeltaWidth(float deltaWidth) Sets the per-update width delta applied to the particle.setFade(boolean fade) Sets whether the particle fades out over its lifetime.setFadeOnCollision(boolean fadeOnCollision) Sets whether the particle fades upon collision.setHeight(float height) Sets the height of the particle, in pixels.setOutlineOnly(boolean outlineOnly) Sets whether the particle is rendered as an outline only.setOutlineThickness(float outlineThickness) Sets the outline thickness used when rendering the particle as an outline.setStopOnCollision(boolean stopOnCollision) Sets whether the particle stops moving when it collides.setTimeToLive(int ttl) Sets the time-to-live (TTL) of the particle, in milliseconds.setVelocityX(float velocityX) Sets the horizontal velocity of the particle.setVelocityY(float velocityY) Sets the vertical velocity of the particle.setWidth(float width) Sets the width of the particle, in pixels.setX(float x) Sets the X position of the particle relative to its emitter origin.setY(float y) Sets the Y position of the particle relative to its emitter origin.booleanDetermines whether this instance has exceeded its time to live.voidUpdates the effect's position, change in xCurrent, change in yCurrent, remaining lifetime, and color.booleanReturns whether this particle has a custom render type that overrides the emitter's render type.
-
Constructor Details
-
Particle
protected Particle(float width, float height) Constructs a new particle.- Parameters:
width- the particle width in pixelsheight- the particle height in pixels
-
-
Method Details
-
getAliveTime
public long getAliveTime()Description copied from interface:ITimeToLiveGets the time this instance is alive.- Specified by:
getAliveTimein interfaceITimeToLive- Returns:
- Returns how long this instance is alive.
-
getBoundingBox
Gets the current bounding box of the particle, depending on its spawn location.- Parameters:
origin- the spawn location of this particle- Returns:
- The Rectangular particle bounding box.
-
getCollisionType
Gets the collision behavior of this particle.- Returns:
- the collision behavior
-
getColor
-
getDeltaHeight
public float getDeltaHeight()Gets the per-update height delta applied to the particle.- Returns:
- the height delta
-
getDeltaWidth
public float getDeltaWidth()Gets the per-update width delta applied to the particle.- Returns:
- the width delta
-
getVelocityX
public float getVelocityX()Gets the horizontal velocity of the particle.- Returns:
- the horizontal velocity
-
getVelocityY
public float getVelocityY()Gets the vertical velocity of the particle.- Returns:
- the vertical velocity
-
getAccelerationX
public float getAccelerationX()Gets the horizontal acceleration of the particle.- Returns:
- the horizontal acceleration
-
getAccelerationY
public float getAccelerationY()Gets the vertical acceleration of the particle.- Returns:
- the vertical acceleration
-
getAngle
public float getAngle()Gets the current rotation angle of the particle, in degrees.- Returns:
- the current angle
-
getDeltaAngle
public float getDeltaAngle()Gets the per-update angle delta applied to the particle, in degrees.- Returns:
- the angle delta
-
getHeight
public float getHeight()Gets the current height of the particle, in pixels.- Returns:
- the particle height
-
getOutlineThickness
public float getOutlineThickness()Gets the outline thickness used when rendering the particle as an outline.- Returns:
- the outline thickness
-
isOutlineOnly
public boolean isOutlineOnly()Returns whether the particle is rendered as an outline only.- Returns:
trueif outline-only rendering is enabled
-
isAntiAliased
public boolean isAntiAliased()Returns whether the particle is rendered with anti-aliasing.- Returns:
trueif anti-aliasing is enabled
-
getOpacity
public float getOpacity()Computes the current opacity of the particle. If fading is enabled and the particle has a finite time-to-live, the opacity decreases linearly from the color's initial alpha towards zero as the particle ages.- Returns:
- the opacity in the range
[0, 1]
-
getRenderLocation
-
getCustomRenderType
Gets the custom render type that overrides the emitter's render type, ifusesCustomRenderType()istrue.- Returns:
- the custom render type
-
getTimeToLive
public int getTimeToLive()Description copied from interface:ITimeToLiveGets the total time to live of this instance.- Specified by:
getTimeToLivein interfaceITimeToLive- Returns:
- The total time to live.
-
getWidth
public float getWidth()Gets the current width of the particle, in pixels.- Returns:
- the particle width
-
getX
public float getX()Gets the X position of the particle relative to its emitter origin.- Returns:
- the X position
-
getY
public float getY()Gets the Y position of the particle relative to its emitter origin.- Returns:
- the Y position
-
isFading
public boolean isFading()Returns whether the particle fades out over its lifetime.- Returns:
trueif fading is enabled
-
isFadingOnCollision
public boolean isFadingOnCollision()Returns whether the particle fades upon collision.- Returns:
trueif fade-on-collision is enabled
-
isContinuousCollisionEnabled
public boolean isContinuousCollisionEnabled()Returns whether continuous (ray-cast) collision detection is enabled for this particle.- Returns:
trueif continuous collision detection is enabled
-
isStoppingOnCollision
public boolean isStoppingOnCollision()Returns whether the particle stops moving once a collision occurs.- Returns:
trueif the particle stops on collision
-
render
Renders this particle to the given graphics context.- Parameters:
g- the graphics context to draw toemitterOrigin- the world location of the owning emitter
-
setCollisionType
-
setContinuousCollision
Enabling this check can be very performance hungry and should be used with caution and only for a small amount of particles.- Parameters:
ccd- If set to true, the collision will be checked continuously by a ray-cast approximation.- Returns:
- This particle instance.
-
setStopOnCollision
Sets whether the particle stops moving when it collides.- Parameters:
stopOnCollision-trueto stop the particle on collision- Returns:
- this particle instance for chaining
-
setColor
-
setDeltaHeight
Sets the per-update height delta applied to the particle.- Parameters:
deltaHeight- the height delta- Returns:
- this particle instance for chaining
-
setAccelerationX
Sets the horizontal acceleration of the particle.- Parameters:
accelerationX- the horizontal acceleration- Returns:
- this particle instance for chaining
-
setAccelerationY
Sets the vertical acceleration of the particle.- Parameters:
accelerationY- the vertical acceleration- Returns:
- this particle instance for chaining
-
setAngle
Sets the current rotation angle of the particle, in degrees.- Parameters:
angle- the angle to set- Returns:
- this particle instance for chaining
-
setDeltaAngle
Sets the per-update angle delta applied to the particle, in degrees.- Parameters:
deltaAngle- the angle delta- Returns:
- this particle instance for chaining
-
setDeltaWidth
Sets the per-update width delta applied to the particle.- Parameters:
deltaWidth- the width delta- Returns:
- this particle instance for chaining
-
setVelocityX
Sets the horizontal velocity of the particle.- Parameters:
velocityX- the horizontal velocity- Returns:
- this particle instance for chaining
-
setVelocityY
Sets the vertical velocity of the particle.- Parameters:
velocityY- the vertical velocity- Returns:
- this particle instance for chaining
-
setFade
Sets whether the particle fades out over its lifetime.- Parameters:
fade-trueto enable fading- Returns:
- this particle instance for chaining
-
setFadeOnCollision
Sets whether the particle fades upon collision.- Parameters:
fadeOnCollision-trueto enable fade-on-collision- Returns:
- this particle instance for chaining
-
setHeight
Sets the height of the particle, in pixels.- Parameters:
height- the height to set- Returns:
- this particle instance for chaining
-
setOutlineThickness
Sets the outline thickness used when rendering the particle as an outline.- Parameters:
outlineThickness- the outline thickness- Returns:
- this particle instance for chaining
-
setOutlineOnly
Sets whether the particle is rendered as an outline only.- Parameters:
outlineOnly-trueto enable outline-only rendering- Returns:
- this particle instance for chaining
-
setAntiAliasing
Sets whether the particle is rendered with anti-aliasing.- Parameters:
antiAliasing-trueto enable anti-aliasing- Returns:
- this particle instance for chaining
-
setCustomRenderType
Sets a custom render type that overrides the emitter's render type for this particle.- Parameters:
renderType- the render type to use- Returns:
- this particle instance for chaining
-
setWidth
Sets the width of the particle, in pixels.- Parameters:
width- the width to set- Returns:
- this particle instance for chaining
-
setX
Sets the X position of the particle relative to its emitter origin.- Parameters:
x- the X position- Returns:
- this particle instance for chaining
-
setY
Sets the Y position of the particle relative to its emitter origin.- Parameters:
y- the Y position- Returns:
- this particle instance for chaining
-
setTimeToLive
Sets the time-to-live (TTL) of the particle, in milliseconds.- Parameters:
ttl- the TTL to set- Returns:
- this particle instance for chaining
-
init
Initializes this particle's mutable state from the suppliedEmitterAttributes.- Parameters:
data- the emitter data providing initial parameter values- Returns:
- this particle instance for chaining
-
timeToLiveReached
public boolean timeToLiveReached()Description copied from interface:ITimeToLiveDetermines whether this instance has exceeded its time to live.- Specified by:
timeToLiveReachedin interfaceITimeToLive- Returns:
- True if the time to live was reached; otherwise false.
-
update
-
hasRayCastCollision
-
getAbsoluteLocation
-
getAbsoluteX
Computes the absolute world X coordinate of this particle, accounting for the particle's width.- Parameters:
emitterOrigin- the emitter origin- Returns:
- the absolute X coordinate
-
getAbsoluteY
Computes the absolute world Y coordinate of this particle, accounting for the particle's height.- Parameters:
emitterOrigin- the emitter origin- Returns:
- the absolute Y coordinate
-
usesCustomRenderType
public boolean usesCustomRenderType()Returns whether this particle has a custom render type that overrides the emitter's render type.- Returns:
trueif a custom render type is set
-