CPParticleSprite

class CPParticleSprite(id: String, emitters: Seq[CPParticleEmitter], collidable: Boolean, shaders: Seq[CPShader]) extends CPSceneObject

Scene object tailor-made for rendering particle effect.

Particle sprite is part of the particle effect animation support. Particle effect support consists of three key components:

Particle defines a single-pixel element (a-la mini-sprite) that has its own lifecycle and gets updated on each frame update. Particle emitter is a components that is responsible for creating particles. And particle sprite ties all that together into single renderable component. Particle sprite can have one or more particle emitters and each emitter can create multiple particles. One of the key features of particle effect support is its modularity: particle implementation can be reused by multiple emitters, and an emitter implementation can be reused by multiple independent particle sprites.

Sprites

CosPlay provides number of built-in sprites. A sprite is a scene objects, visible or off-screen, that is custom designed for a particular use case. Built-in sprites provide concrete implementations for the abstract methods in the base CPSceneObject class. Most non-trivial games will use combination of the built-in sprites and their own ones. Here's the list of the built-in sprites:

Value parameters:
collidable

Whether or not this sprite provides collision shape. Defualt value is false.

emitters

Set of particle emitters this sprite will use.

id

Optional ID of the sprite.

shaders

Optional sequence of shaders for this sprite. Default value is an empty sequence.

Example:

See CPParticleExample class for the example of using particle effect.

Source:
CPParticleSprite.scala
class Object
trait Matchable
class Any

Value members

Concrete methods

override def getCollisionRect: Option[CPRect]

Gets optional collision shape or hit box for this sprite.

Gets optional collision shape or hit box for this sprite.

Definition Classes
Source:
CPParticleSprite.scala
override def getDim: CPDim

Gets current dimension (width and height) of this object.

Gets current dimension (width and height) of this object.

Definition Classes
Source:
CPParticleSprite.scala
override def getRect: CPRect

Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.

Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.

Definition Classes
Source:
CPParticleSprite.scala
override def getShaders: Seq[CPShader]

Gets the optional list of shaders attached to this scene object. By default, returns an empty list. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

Gets the optional list of shaders attached to this scene object. By default, returns an empty list. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

Definition Classes
Source:
CPParticleSprite.scala
override def getX: Int

Gets current X-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Gets current X-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Definition Classes
Source:
CPParticleSprite.scala
override def getY: Int

Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Definition Classes
Source:
CPParticleSprite.scala
override def getZ: Int

Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.

Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.

Definition Classes
Source:
CPParticleSprite.scala
def hasLiveParticles: Boolean

Tests whether this sprite has any live particle remaining.

Tests whether this sprite has any live particle remaining.

Source:
CPParticleSprite.scala
def isPaused: Boolean

Tests whether all emitters are paused or not.

Tests whether all emitters are paused or not.

Source:
CPParticleSprite.scala
def pause(): Unit

Pauses all emitters by calling their CPParticleEmitter.pause method.

Pauses all emitters by calling their CPParticleEmitter.pause method.

Source:
CPParticleSprite.scala
override def render(ctx: CPSceneObjectContext): Unit

Called to render this scene object. Only visible and in camera frame objects will receive this callback. This callback is called on scene object after all scene objects received update callback. Note that unlike update callbacks and shaders that are called for all scene objects on each frame, this callback is only called for scene objects that are visible and, at least partially, in camera frame.

Called to render this scene object. Only visible and in camera frame objects will receive this callback. This callback is called on scene object after all scene objects received update callback. Note that unlike update callbacks and shaders that are called for all scene objects on each frame, this callback is only called for scene objects that are visible and, at least partially, in camera frame.

Definition Classes
Source:
CPParticleSprite.scala
def reset(): Unit

Resets all emitters to their initial state by calling their CPParticleEmitter.reset method.

Resets all emitters to their initial state by calling their CPParticleEmitter.reset method.

Source:
CPParticleSprite.scala
def resume(reset: Boolean): Unit

Resumes all emitters by calling their CPParticleEmitter.resume method.

Resumes all emitters by calling their CPParticleEmitter.resume method.

Value parameters:
reset

Whether or not to reset the emitter before resuming its emission.

Source:
CPParticleSprite.scala
def setOnEnd(fun: Option[CPSceneObjectContext => Unit]): Unit

Sets or removes the callback for the end of the effect. End of the effect is defined as first game frame when there are no live particles remained. Note that if the effect is cyclical the callback will be called everytime the end of effect is detected.

Sets or removes the callback for the end of the effect. End of the effect is defined as first game frame when there are no live particles remained. Note that if the effect is cyclical the callback will be called everytime the end of effect is detected.

Value parameters:
fun

Callback function to set or None to remove any previously set callback.

See also:
Source:
CPParticleSprite.scala
def setOnStart(fun: Option[CPSceneObjectContext => Unit]): Unit

Sets or removes the callback for the start of the effect. Start of the effect is defined as first game frame when the first particle was emitted. Note that if the effect is cyclical the callback will be called everytime the start of the effect is detected.

Sets or removes the callback for the start of the effect. Start of the effect is defined as first game frame when the first particle was emitted. Note that if the effect is cyclical the callback will be called everytime the start of the effect is detected.

Value parameters:
fun

Callback function to set or None to remove previously set callback.

See also:
Source:
CPParticleSprite.scala
def toggle(): Unit

Toggles pause state of all emitters by calling their CPParticleEmitter.toggle method. Note that with this method you don't have the control of resetting the emitter before resuming its emission.

Toggles pause state of all emitters by calling their CPParticleEmitter.toggle method. Note that with this method you don't have the control of resetting the emitter before resuming its emission.

Source:
CPParticleSprite.scala
override def update(ctx: CPSceneObjectContext): Unit

Called to update the internal state of this scene object. This callback is called each frame on every object in the scene and it is called before any render callback. Note that all scene object will receive this callback before first render callback.

Called to update the internal state of this scene object. This callback is called each frame on every object in the scene and it is called before any render callback. Note that all scene object will receive this callback before first render callback.

Definition Classes
Source:
CPParticleSprite.scala

Inherited methods

override def equals(obj: Any): Boolean
Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala
inline def getHeight: Int

Gets current height of this object.

Gets current height of this object.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Inherited from:
CPGameObject
Source:
CPGameObject.scala
final def getState: State

Gets current lifecycle state.

Gets current lifecycle state.

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def getTags: Set[String]

Gets optional set of organizational tags. Note that by default the set of tags is empty.

Gets optional set of organizational tags. Note that by default the set of tags is empty.

See also:
Inherited from:
CPGameObject
Source:
CPGameObject.scala
inline def getWidth: Int

Gets current width of this object.

Gets current width of this object.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def hide(): Unit

Shortcut method for hiding this object. Note that by default all scene objects are visible.

Shortcut method for hiding this object. Note that by default all scene objects are visible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def isVisible: Boolean

Checks the visibility flag.

Checks the visibility flag.

If object is invisible than only update method will be called on each frame. If object is visible and in camera frame - method render will be called as well to render itself. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def onActivate(): Unit

Callback on lifecycle object activation. Default implementation is no-op.

Callback on lifecycle object activation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_ACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onDeactivate(): Unit

Callback on lifecycle object deactivation. Default implementation is no-op.

Callback on lifecycle object deactivation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_INACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStart(): Unit

Callback on lifecycle object start. Default implementation is no-op.

Callback on lifecycle object start. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STARTED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStop(): Unit

Callback on lifecycle object stop. Default implementation is no-op.

Callback on lifecycle object stop. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STOPPED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def setVisible(vis: Boolean): Unit

Sets visibility flag. Note that by default all scene objects are visible.

Sets visibility flag. Note that by default all scene objects are visible.

Value parameters:
vis

true to make this object visible, false otherwise.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def show(): Unit

Shortcut method for showing this object. Note that by default all scene objects are visible.

Shortcut method for showing this object. Note that by default all scene objects are visible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala