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 stop sound
Jesse Freeman edited this page Nov 11, 2021
·
1 revision
Use StopSound() to stop any sound playing on a specific channel.
StopSound ( channel )| Name | Value | Description |
|---|---|---|
| channel | int | The channel ID to stop a sound on. |
In this example, we toggle between playing and stopping a sound effect based on the mouse button being released. Running this code will output the following:
![]()
-- Store the playback state of channel 0
local isPlaying = false
function Init()
-- Example Title
DrawText("StopSound()", 8, 8, DrawMode.TilemapCache, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
end
function Update(timeDelta)
-- See if the channel has audio playing back on it
isPlaying = IsChannelPlaying(0)
-- Test if the left mouse button was released and if isPlaying equals false
if(MouseButton(0, InputState.Released)) then
-- Check to see if the channel is playing a sound
if(isPlaying) then
-- Stop the sound
StopSound(0)
else
-- Play the second sound effect
PlaySound(1)
end
end
end
function Draw()
-- Redraw display
RedrawDisplay()
-- Test to see if the sound effect is playing
if(isPlaying) then
-- Draw the sound playback label
DrawText("Click To Stop Sound Effect", 8, 32, DrawMode.Sprite, "large", 14)
else
-- Draw the instructions label
DrawText("Click To Play Sound Effect", 8, 32, DrawMode.Sprite, "large", 15)
end
endnamespace PixelVision8.Player
{
class StopSoundExample : GameChip
{
// Store the playback state of channel 0
private bool isPlaying = false;
public override void Init()
{
// Example Title
DrawText("StopSound()", 8, 8, DrawMode.TilemapCache, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
}
public override void Update(int timeDelta)
{
// See if the channel has audio playing back on it
isPlaying = IsChannelPlaying(0);
// Test if the left mouse button was released and if isPlaying equals false
if (MouseButton(0, InputState.Released))
{
// Check to see if the channel is playing a sound
if (isPlaying)
{
// Stop the sound
StopSound(0);
}
else
{
// Play the second sound effect
PlaySound(1);
}
}
}
public override void Draw()
{
// Redraw display
RedrawDisplay();
// Test to see if the sound effect is playing
if (isPlaying)
{
// Draw the sound playback label
DrawText("Click To Stop Sound Effect", 8, 32, DrawMode.Sprite, "large", 14);
}
else
{
// Draw the instructions label
DrawText("Click To Play Sound Effect", 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