Sprite #
PhpTui\Tui\Extension\Core\Shape\SpriteShape
Renders a “sprite” based on a given “ascii art”
Each sprite can have a single color but they can be layered on the canvas.
Example #
Show code
<?php
declare(strict_types=1);
use PhpTui\Tui\Canvas\Marker;
use PhpTui\Tui\Color\AnsiColor;
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Shape\SpriteShape;
use PhpTui\Tui\Extension\Core\Widget\CanvasWidget;
use PhpTui\Tui\Position\FloatPosition;
require 'vendor/autoload.php';
$display = DisplayBuilder::default()->build();
$display->draw(
CanvasWidget::fromIntBounds(0, 30, 0, 15)
->marker(Marker::Block)
->draw(
new SpriteShape(
rows: [
' XXX ',
'X X ',
'X X ',
' XXX ',
' X',
'XXXXX',
' X ', // rows do not need
' X ', // equals numbers of chars
' X X ',
'X X ',
],
color: AnsiColor::White,
position: FloatPosition::at(2, 2),
)
)
);
Parameters #
Configure the shape using the builder methods named as follows:
Name | Type | Description |
---|---|---|
rows | array | Set of lines/rows which make up the Sprite. e.g. [' ', ' x '] . The lines do not have to be of equal length. |
color | PhpTui\Tui\Color\Color | Color of the sprite |
position | PhpTui\Tui\Position\FloatPosition | Position to place the sprite at (bottom left) |
alphaChar | string | Character to use as the “alpha” (transparent) “channel”. Defaults to empty space. |
xScale | float | X scale |
yScale | float | Y scale |