CPSparkleShader

org.cosplay.prefabs.shaders.CPSparkleShader
class CPSparkleShader(entireFrame: Boolean, colors: Seq[CPColor], ratio: Float, steps: Int, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, durMs: Long, onDuration: CPSceneObjectContext => Unit) extends CPDurationShader

Color sparkle shader.

This shader provides color sparkle effect for the entire camera frame. Sparkling consists of picking number of random pixels on the frame and gradually dimming and brightening their colors creating a sparkling effect. Not that unlike CPShimmerShader that produces a random color changes, this shader relies on smooth gradual dimming and brightening. Both effects are visually similar but work differently.

Value parameters

autoStart

Whether to start shader right away. Default value is false.

colors

Set of color to use for sparking effect. Colors will be randomly chosen for each pixel.

durMs

Duration of the effect in milliseconds. By default, the effect will go forever. It can changed later.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onDuration

Optional callback to call when this shader finishes by exceeding the duration specified by durMs parameter. Default is a no-op.

ratio

Percentage of pixels to sparkle at the same time. Default value is 0.04, i.e. 4%. For example, if the camera frame size is 100x50 characters then the default 4% ratio will result in 200 pixels sparkling at any given time.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

steps

Number of frames that it takes for entire sparkle cycle from brightening to dimming back.

Attributes

See also
Example

See CPShaderExample class for the example of using shaders.

See org.cosplay.games.pong.CPPongTitleScene game scene for example of using this shader.

Source
CPSparkleShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
Show all

Members list

Type members

Classlikes

case class Sparkle(zpx: CPZPixel, x: Int, y: Int)

Attributes

Source
CPSparkleShader.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def isActive: Boolean

Tests whether this shader is in progress or not.

Tests whether this shader is in progress or not.

Attributes

Source
CPSparkleShader.scala
override def render(ctx: CPSceneObjectContext, objRect: CPRect, inCamera: Boolean): Unit

Called on each frame pass on scene object that has this shaders attached to it. This callback is called regardless of whether or not the scene object is visible or in camera frame.

Called on each frame pass on scene object that has this shaders attached to it. This callback is called regardless of whether or not the scene object is visible or in camera frame.

Attributes

Definition Classes
Source
CPSparkleShader.scala
def setDuration(durMs: Long): Unit

Sets the duration in millisecond for this shader effect.

Sets the duration in millisecond for this shader effect.

Value parameters

durMs

Duration of the fade in effect in milliseconds.

Attributes

Source
CPSparkleShader.scala
def start(): Unit

Starts the shader effect.

Starts the shader effect.

Attributes

See also
Source
CPSparkleShader.scala
def stop(): Unit

Stops the shader effect without waiting for the duration. Note that onDuration() callback will not be called in this case.

Stops the shader effect without waiting for the duration. Note that onDuration() callback will not be called in this case.

Attributes

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

Toggles this shader effect on and off by calling either start or stop methods.

Toggles this shader effect on and off by calling either start or stop methods.

Attributes

See also
Source
CPSparkleShader.scala

Inherited methods

protected def checkBgPixel(bgPx: CPPixel): Unit

Attributes

Inherited from:
CPDurationShader
Source
CPDurationShader.scala
protected def checkDuration(durMs: Long): Unit

Attributes

Inherited from:
CPDurationShader
Source
CPDurationShader.scala

Inherited fields

override val getOrigin: String

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Attributes

Inherited from:
CPShader
Source
CPShader.scala