CPStarStreakShader
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