CPStarStreakShader

org.cosplay.prefabs.shaders.CPStarStreakShader
class CPStarStreakShader(entireFrame: Boolean, bg: CPColor, var streaks: Seq[CPStarStreak], autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, durMs: Long, onDuration: CPSceneObjectContext => Unit) extends CPShader

Star streak shader.

This shader produces a star streak effect with one or more streaks. Each streak defined by CPStarStreak class provides unique configuration for the set of stars: its character to render with, number of stars relative to the size of the current canvas, colors to use for fading, its lifetime, speed and direction to move and z-index. Each such set of stars can "streak" differently, e.g. providing parallax effect.

For example, here's an example of using this shader in the built-in Snake game for parallax starry skies effect on its title scene:

private val starStreakShdr = CPStarStreakShader(
   true,
   BG_PX.bg.get,
    Seq(
        CPStarStreak('.', CS, 0.025, 30, (-.5f, 0f), 0),
        CPStarStreak('.', CS, 0.015, 25, (-1.5f, 0f), 0),
        CPStarStreak('_', CS, 0.005, 20, (-2.0f, 0f), 0)
    ),
    skip = (zpx, _, _) => zpx.z == 1
)

Value parameters

autoStart

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

bg

Background color to fade into.

durMs

Duration of the effect in milliseconds. By default, the effect will go forever.

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.

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.

Attributes

See also
Example

See CPShaderExample class for the example of using shaders.

See org.cosplay.games.snake.CPSnakeTitleScene game scene for example of using this shader.

Source
CPStarStreakShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

Gets this shader's set of star streaks.

Gets this shader's set of star streaks.

Attributes

Source
CPStarStreakShader.scala
def isActive: Boolean

Tests whether this shader is in progress or not.

Tests whether this shader is in progress or not.

Attributes

Source
CPStarStreakShader.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
CPStarStreakShader.scala
def setStreaks(streaks: Seq[CPStarStreak]): Unit

Sets new set of star streaks.

Sets new set of star streaks.

Value parameters

streaks

Star streaks to set.

Attributes

Source
CPStarStreakShader.scala
def start(): Unit

Starts the shader effect.

Starts the shader effect.

Attributes

See also
Source
CPStarStreakShader.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
CPStarStreakShader.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
CPStarStreakShader.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