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 clamp
Jesse Freeman edited this page Nov 11, 2021
·
1 revision
The Clamp() API limits a value between a minimum and maximum integer.
Clamp ( val, min, max )| Name | Value | Description |
|---|---|---|
| val | int | The value to clamp. |
| min | int | The minimum value should be. |
| max | int | The maximum value should be. |
| Value | Description |
|---|---|
| int | Returns an int within the min and max range. |
In this example, we will increase the number by 1 every frame and clamp it at 100.
Running this code will output the following:
![]()
local counter = 0
local time = 0
local delay = 300
function Init()
-- Example Title
DrawText("Clamp()", 8, 8, DrawMode.TilemapCache, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
end
function Update(timeDelta)
-- Add the time delay to the time
time = time + timeDelta
-- Check if time is greater than the delay
if(time > delay) then
-- Increase the counter by 1
counter = Clamp(counter + 1, 0, 10)
-- Reset the time
time = 0
end
end
function Draw()
-- Redraw the display
RedrawDisplay()
-- Draw the counter to the display
DrawText("Counter " .. counter, 8, 32, DrawMode.Sprite, "large", 15)
endnamespace PixelVision8.Player
{
class ClampExample : GameChip
{
private int counter;
private int time;
private int delay = 300;
public override void Init()
{
// Example Title
DrawText("Clamp()", 8, 8, DrawMode.TilemapCache, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
}
public override void Update(int timeDelta)
{
// Add the time delay to the time
time = time + timeDelta;
// Check if time is greater than the delay
if (time > delay)
{
// Increase the counter by 1
counter = Clamp(counter + 1, 0, 10);
// Reset the time
time = 0;
}
}
public override void Draw()
{
// Redraw the display
RedrawDisplay();
// Draw the counter to the display
DrawText("Counter " + counter, 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