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 )
Whether to start shader right away. Default value is
Background color to fade into.
Duration of the effect in milliseconds. By default, the effect will go forever.
Whether apply to the entire camera frame or just the object this shader is attached to.
Optional callback to call when this shader finishes by exceeding the duration specified by
durMsparameter. Default is a no-op.
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
falsefor all pixels.
- See also
See CPShaderExample class for the example of using shaders.
See org.cosplay.games.snake.CPSnakeTitleScene game scene for example of using this shader.
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.
Stops the shader effect without waiting for the duration. Note that
onDuration() callback will not be called in this case.
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.