ice.graphicseffect
Procedural graphics effects.
- abstract class GraphicsEffect;
Base class for procedural graphics effects.
These are usually used for various fullscreen effects that don't depend on game entities.
Managed and drawn by GraphicsEffectManager.Signal:
public mixin Signal!() onExpired
Emitted when the effect expires.- class RandomLinesEffect: ice.graphicseffect.GraphicsEffect;
Effect that draws lines at random coordinates, optionally vertically scrolling them.
Effect parameters are specified each frame by a delegate.
The delegate takes a real specifying time when the effect started, current time and a reference to effect parameters. It returns a boolean that is true when the effect is done and should expire.Example:
//This draws an an increasing number of slowly moving vertical lines in the game area. //It is taken from the Game class, and uses its data members. //Anyone is welcome to create a simpler example not depending on Game. GraphicsEffect effect = new RandomLinesEffect(gameTime_.gameTime, (const real startTime, const real currentTime, ref RandomLinesEffect.Parameters params) { const double timeRatio = (currentTime - startTime) / 3.0; if(timeRatio > 1.0){return true;} params.bounds = Game.gameArea; params.minWidth = 0.3; params.maxWidth = 2.0; params.minLength = 4.0f; params.maxLength = 16.0f; params.linesPerPixel = round!uint((40 * clamp(timeRatio, 0.0, 1.0)) ^^ 2) Game.gameArea.area; params.color = rgba!"8080F040"; params.detailLevel = 4; params.verticalScrollingSpeed = 100.0f; return false; });
- struct Parameters;
-
- Rectf bounds;
Bounds of the area where the lines are drawn.
- Vector2f lineDirection;
Direction of the lines. Must be a unit (length == 1) vector.
- float minWidth;
Minimum line width.
- float maxWidth;
Maximum line width. Must be > minWidth.
- float minLength;
Minimum line length.
- float maxLength;
Maximum line length. Must be > minLength.
- float linesPerPixel;
Average number of lines per "pixel" of area specified by bounds.
"Pixel" is a square of distance of 1.0 unit. Must be <= 1.0;
- float verticalScrollingSpeed;
Speed of vertical scrolling in units per second.
- uint detailLevel;
Higher values result in less random, less "detailed" effect but less overhead.
0 is "full" detail and rather CPU-intensive. 1 is less detail but a lot cheaper performance-wise. Higher values are even cheaper.
- Color color;
Color of lines.
- const pure nothrow bool valid();
- this(const(real) startTime, bool delegate(const(real), const(real), ref Parameters) controlDelegate);
Construct a RandomLinesEffect starting at startTime using controlDelegate to set its parameters.
- class ScrollingTextLinesEffect: ice.graphicseffect.GraphicsEffect;
Effect that draws vertically scrolling text lines.
Effect parameters are specified each frame by a delegate.
The delegate takes a real specifying time when the effect started, current time and a reference to effect parameters. It returns a boolean that is true when the effect is done and should expire.Example:
//This draws a scrolling (upwards) column of text where each line //is a randomly selected number from a list. GraphicsEffect effect = new ScrollingTextLinesEffect(getTime(), (const real startTime, const real currentTime, ref ScrollingTextLinesEffect.Parameters params) { params.lineStrings = [ "1536", "7233", "4287", "8923", "2342", "32583", "7896", "2352", "22358", "2423" ]; params.randomOrder = Yes.randomOrder; params.position = Vector2i(16, -16); params.scrollingSpeed = -100.0f; params.fontColor = rgba!"E8E8FF90"; params.fontSize = 12; params.randomOrder = No.randomOrder; params.font = "orbitron-bold.ttf"; params.lineCount = 48; return false; });
- struct Parameters;
-
- string[] lineStrings;
Strings of the scrolled text. Each string is one line.
At least 1 string is required.
- float scrollingSpeed;
Scrolling speed of the text in units per second. Can be negative.
- Flag!("randomOrder") randomOrder;
Should the lines be scrolled in random order?
- Color fontColor;
Color of the scrolled text.
- uint fontSize;
Font size of the scrolled text.
- string font;
Font of the scrolled text.
- Vector2i position;
Position of the upper-left corner of the scrolled text.
- uint lineCount;
Number of lines of scrolled text.
If more than lineStrings.length, the same strings will be reused for multiple lines. Must be at least 1.
- this(const(real) startTime, bool delegate(const(real), const(real), ref Parameters) controlDelegate);
Construct a ScrollingTextLinesEffect starting at startTime using controlDelegate to set its parameters.
- class TextEffect: ice.graphicseffect.GraphicsEffect;
Text effect.
Draws text with parameters specified each frame by a delegate.
The delegate takes a real specifying time when the effect started, current time and a reference to effect parameters. It returns a boolean that is true when the effect is done and should expire.Example:
//This draws an enlarging, fading text in the middle of the game area. //It is taken from the Game class, and uses its data members. //Anyone is welcome to create a simpler example not depending on Game. GraphicsEffect effect = new TextEffect(gameTime_.gameTime, (const real startTime, const currentTime, ref TextEffect.Parameters params) { const double timeRatio = (currentTime - startTime) / 1.5; if(timeRatio > 1.0){return true;} auto gameOver = "GAME OVER"; params.text = gameOver; params.font = "default"; params.fontSize = 80 + round!uint(max(0.0, timeRatio * 16.0) ^^ 2); //Must set videodriver font and font size to measure text size. videoDriver_.font = "default"; videoDriver_.fontSize = params.fontSize; const textSize = videoDriver_.textSize(params.text).to!float; const area = Game.gameArea; params.offset = (area.min + (area.size - textSize) * 0.5).to!int; params.color = rgba!"8080F080".interpolated(rgba!"8080F000", 1.0 - timeRatio ^^ 2); return false; });
- class GraphicsEffectManager;
Manages graphics effects.