This repository was archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 120
api split lines
Jesse Freeman edited this page Nov 11, 2021
·
1 revision
The SplitLines() API converts text with line breaks (\n) into an array. This can be used in conjunction with the WordWrap() helper to render large blocks of text line by line with the DrawText() API.
SplitLines ( str )| Name | Value | Description |
|---|---|---|
| str | string | The string of text to split. |
| Value | Description |
|---|---|
| string[] | Returns an array of strings representing each line of text. |
In this example, we are going to use the SplitLines() API to create an array of text to draw to the display. Running this code will output the following:
![]()
-- Message to display on the screen
local message = "PIXEL VISION 8\n\nVisit 'pixelvision8.com' to learn more about creating games from scratch."
function Init()
-- Example Title
DrawText("SplitLines()", 8, 8, DrawMode.TilemapCache, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
-- To convert the message into lines of text we need to wrap it then split it
local wrap = WordWrap(message, (Display().x / 8) - 2)
local lines = SplitLines(wrap)
-- Loop through each line of text and draw it to the display
for i = 1, #lines do
DrawText(lines[i], 1, i + 4, DrawMode.Tile, "large", 15)
end
end
function Draw()
-- Redraw the display
RedrawDisplay()
endnamespace PixelVision8.Player
{
class SplitLinesExample : GameChip
{
// Message to display on the screen
private string message = "PIXEL VISION 8\n\nVisit 'pixelvision8.com' to learn more about creating games from scratch.";
public override void Init()
{
// Example Title
DrawText("SplitLines()", 8, 8, DrawMode.TilemapCache, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
// To convert the message into lines of text we need to wrap it then split it
var wrap = WordWrap(message, (Display().X / 8) - 2);
var lines = SplitLines(wrap);
// Loop through each line of text and draw it to the display
for (int i = 0; i < lines.Length; i++)
{
DrawText(lines[i], 1, i + 1 + 4, DrawMode.Tile, "large", 15);
}
}
public override void Draw()
{
// Redraw the display
RedrawDisplay();
}
}
}- Game Project
- Lua Games (coming soon)
- C# Sharp Games
- C# Sharp Vs Lua
- API Cheat Sheet
- Enums
- Visual Studio Code
- Atom
- Tiled (Coming Soon)
- Aseprite (Coming Soon)
- AddScript
- BackgroundColor
- Button
- CalculateDistance
- CalculateIndex
- CalculatePosition
- CharacterToPixelData
- Clamp
- Clear
- Color
- ColorsPerSprite
- Display
- DrawMetaSprite
- DrawPixels
- DrawRect
- DrawSprite
- DrawText
- DrawTilemap
- Flag
- InputString
- IsChannelPlaying
- Key
- LoadTilemap
- MaxSpriteCount
- MouseButton
- MousePosition
- NewCanvas
- NewPoint
- NewRect
- PaletteOffset
- PauseSong
- PlaySong
- PlaySound
- ReadAllMetadata
- ReadMetadata
- ReadSaveData
- RedrawDisplay
- Repeat
- ReplaceColor
- RewindSong
- ScrollPosition
- SongData
- Sound
- SplitLines
- SpriteSize
- Sprite
- StopSong
- StopSound
- Tile
- TilemapSize
- TotalColors
- TotalSprites
- UpdateTiles
- WordWrap
- WriteSaveData