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 119
api repeat
Jesse Freeman edited this page Nov 11, 2021
·
1 revision
The Repeat()
API allows you to reset the value of a number if it goes past a maximum value. When counting backward, Repeat()
will set the value to the maximum when below 0.
Repeat ( val, max )
Name | Value | Description |
---|---|---|
val | int | The value to repeat. |
max | int | The maximum the value can be. |
Value | Description |
---|---|
int | Returns an int that is never less than 0 or greater than the max. |
In this example, we will increase a counter by 1
on every frame and use Repeat()
to have it wrap back to 0
when it goes greater than the max value. Running this code will output the following:
-- Store the counter value and max value
local counter = 0
local counterMax = 500
function Init()
-- Example Title
DrawText("Repeat()", 8, 8, DrawMode.TilemapCache, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
end
function Update(timeDelta)
-- Increase the counter by 1 every frame
counter = Repeat(counter + 1, counterMax)
end
function Draw()
-- Redraw display
RedrawDisplay()
-- Draw the counter value to the display
DrawText("Counter " .. counter .. "/" .. counterMax, 8, 32, DrawMode.Sprite, "large", 15)
end
namespace PixelVision8.Player
{
class RepeatExample : GameChip
{
// Store the counter value and max value
private int counter;
private int counterMax = 500;
public override void Init()
{
// Example Title
DrawText("Repeat()", 8, 8, DrawMode.TilemapCache, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
}
public override void Update(int timeDelta)
{
// Increase the counter by 1 every frame
counter = Repeat(counter + 1, counterMax);
}
public override void Draw()
{
// Redraw display
RedrawDisplay();
// Draw the counter value to the display
DrawText("Counter " + counter + "/" + counterMax, 8, 32, DrawMode.Sprite, "large", 15);
}
}
}
- 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