Getting Started with 2D Games Using Arcade Library (Part 10): Playing Sound Effects

Published: (December 24, 2025 at 07:07 AM EST)
5 min read
Source: Dev.to

Source: Dev.to

Prepare Sound Files

Create a new sounds folder and place the following sound file inside it.

SoundFile Name
Download se_coin.oggse_coin.ogg

If you cannot download the file directly from GitHub, please use the Download button at the top‑right of the page.

The folder structure should look like this:

# Folder structure
working_directory/
├─ main.py
├─ sprite.py
├─ images/
└─ sounds/        # Folder for sound files
   └─ se_coin.ogg

Create a Sound Object

By passing the path to a sound file into arcade.Sound(), you can create a sound object.

# main.py (excerpt)

# Sound object
self.se_coin = arcade.Sound("sounds/se_coin.ogg")

Play the Sound

You can play the created sound object by passing it to arcade.play_sound().

# main.py (excerpt)

# Play the sound
arcade.play_sound(self.se_coin)

If you cannot hear any sound, please check:

  • Your PC volume or mute settings
  • Whether the path to the sound file is correct

Complete Code

Below is the complete code with all features implemented so far. You can copy and run it as‑is.

sprite.py (complete)

import arcade
import math

class BaseSprite(arcade.Sprite):
    def __init__(self, filename, x, y):
        super().__init__(filename)
        # Position
        self.center_x = x
        self.center_y = y
        # Velocity
        self.vx = 0
        self.vy = 0
        # Animation
        self.anim_counter = 0
        self.anim_interval = 4
        self.anim_index = 0
        self.anim = []

    def update(self, delta_time):
        """Update position and animation."""
        self.center_x += self.vx * delta_time
        self.center_y += self.vy * delta_time
        self.update_animation()

    def move(self, spd, deg):
        """Move sprite."""
        rad = deg * math.pi / 180
        self.vx = spd * math.cos(rad)
        self.vy = spd * math.sin(rad)

    def stop(self):
        """Stop sprite."""
        self.vx = 0
        self.vy = 0

    def update_animation(self):
        """Handle frame animation."""
        if not self.anim:
            return
        self.anim_counter += 1
        if self.anim_counter < self.anim_interval:
            return
        self.anim_counter = 0
        self.anim_index = (self.anim_index + 1) % len(self.anim)
        self.texture = self.anim[self.anim_index]

class Player(BaseSprite):
    def __init__(self, filename, x, y):
        super().__init__(filename, x, y)

        self.anim.extend([
            arcade.load_texture("images/ninja/front_01.png"),
            arcade.load_texture("images/ninja/front_02.png"),
            arcade.load_texture("images/ninja/front_03.png"),
            arcade.load_texture("images/ninja/front_04.png"),
            arcade.load_texture("images/ninja/front_05.png"),
        ])

class Coin(BaseSprite):
    def __init__(self, filename, x, y):
        super().__init__(filename, x, y)

        self.anim.extend([
            arcade.load_texture("images/coin/coin_01.png"),
            arcade.load_texture("images/coin/coin_02.png"),
            arcade.load_texture("images/coin/coin_03.png"),
            arcade.load_texture("images/coin/coin_04.png"),
            arcade.load_texture("images/coin/coin_05.png"),
        ])

main.py (complete)

import arcade
import random
import sprite

class GameView(arcade.View):
    def __init__(self, window):
        super().__init__()
        self.window = window
        self.w = self.window.width
        self.h = self.window.height

        # Background color
        self.background_color = arcade.color.PAYNE_GREY

        # Background sprites
        self.backgrounds = arcade.SpriteList()
        bkg = arcade.Sprite("images/bg_temple.png")
        bkg.center_x = self.w / 2
        bkg.center_y = self.h / 2
        self.backgrounds.append(bkg)

        # Player sprite
        self.players = arcade.SpriteList()
        self.player = sprite.Player(
            "images/ninja/front_01.png",
            x=self.w / 2,
            y=self.h / 2,
        )
        self.players.append(self.player)

        # Coin sprites
        self.coins = arcade.SpriteList()
        for _ in range(10):
            x = random.random() * self.w
            y = random.random() * self.h
            coin = sprite.Coin(
                "images/coin/coin_01.png",
                x=x,
                y=y,
            )
            self.coins.append(coin)

        # Score
        self.score = 0
        self.score_text = arcade.Text(
            f"SCORE: {self.score}",
            self.w / 2,
            self.h - 20,
            arcade.color.BLACK,
            16,
            anchor_x="center",
            anchor_y="top",
        )

        # Sound object
        self.se_coin = arcade.Sound("sounds/se_coin.ogg")

    def on_key_press(self, key, key_modifiers):
        # Move (WASD)
        if key == arcade.key.W:
            self.player.move(90, 90)
        if key == arcade.key.A:
            self.player.move(90, 180)
        if key == arcade.key.S:
            self.player.move(90, 270)
        if key == arcade.key.D:
            self.player.move(90, 0)

    def on_key_release(self, key, key_modifiers):
        # Stop movement when key is released
        if key in (arcade.key.W, arcade.key.A, arcade.key.S, arcade.key.D):
            self.player.stop()

    def on_update(self, delta_time):
        self.players.update(delta_time)
        self.coins.update(delta_time)

        # Check for collisions between player and coins
        hit_list = arcade.check_for_collision_with_list(self.player, self.coins)
        for coin in hit_list:
            self.coins.remove(coin)
            self.score += 1
            self.score_text.text = f"SCORE: {self.score}"
            arcade.play_sound(self.se_coin)

    def on_draw(self):
        arcade.start_render()
        self.backgrounds.draw()
        self.players.draw()
        self.coins.draw()
        self.score_text.draw()

def main():
    window = arcade.Window(800, 600, "Arcade Sound Demo")
    game_view = GameView(window)
    window.show_view(game_view)
    arcade.run()

if __name__ == "__main__":
    main()

Full Code Example

import arcade

class GameView(arcade.View):
    def __init__(self, window):
        super().__init__(window)

        # --- Sprite lists ---
        self.players = arcade.SpriteList()
        self.coins = arcade.SpriteList()
        self.backgrounds = arcade.SpriteList()

        # --- Player sprite ---
        self.player = arcade.Sprite("images/player.png", scale=0.5)
        self.player.center_x = 240
        self.player.center_y = 160
        self.players.append(self.player)

        # --- Coin sprites ---
        for i in range(10):
            coin = arcade.Sprite("images/coin.png", scale=0.3)
            coin.center_x = arcade.rand_in_range(0, 480)
            coin.center_y = arcade.rand_in_range(0, 320)
            self.coins.append(coin)

        # --- Background ---
        bg = arcade.Sprite("images/background.png", scale=1.0)
        self.backgrounds.append(bg)

        # --- Score ---
        self.score = 0
        self.score_text = arcade.Text(
            f"SCORE: {self.score}",
            start_x=10,
            start_y=300,
            color=arcade.color.WHITE,
            font_size=14,
        )

        # --- Sound ---
        self.se_coin = arcade.load_sound("sounds/coin.wav")

    def on_key_press(self, key, key_modifiers):
        if key == arcade.key.W:
            self.player.move(0, 90)
        if key == arcade.key.S:
            self.player.move(0, -90)
        if key == arcade.key.A:
            self.player.move(-90, 0)
        if key == arcade.key.D:
            self.player.move(90, 0)

    def on_key_release(self, key, key_modifiers):
        self.player.stop()

    def on_update(self, delta_time):
        self.players.update(delta_time)
        self.coins.update(delta_time)

        # Check for collisions between the player and any coin
        hit_coins = arcade.check_for_collision_with_list(
            self.player,
            self.coins
        )
        for coin in hit_coins:
            coin.remove_from_sprite_lists()
            # Update score
            self.score += 1
            self.score_text.text = f"SCORE: {self.score}"
            # Play sound
            arcade.play_sound(self.se_coin)

    def on_draw(self):
        self.clear()                     # Clear the screen
        self.backgrounds.draw()
        self.players.draw()
        self.coins.draw()
        self.score_text.draw()

def main():
    """Main process."""
    window = arcade.Window(480, 320, "Hello, Arcade!!")
    game = GameView(window)
    window.show_view(game)
    arcade.run()

if __name__ == "__main__":
    main()

Full‑screen Controls

  • Enter fullscreen mode – press F (or use the window menu).
  • Exit fullscreen mode – press Esc (or use the window menu).

Expected Result

The game should run and the coin‑collect sound will play whenever a coin is collected.

Gameplay demo

Final Thoughts

Thank you very much for reading.

This concludes “Getting Started with 2D Games Using Arcade Library.” Great job finishing the series!!

The game we created is very simple, but it includes all the fundamental elements of game development:

  • Sprite management
  • Keyboard input
  • Sound playback

If you understand everything up to this point, you should now be able to create simple games with Arcade on your own.

I highly recommend using what you’ve learned here as a base and trying to build your own small game.

I hope this series becomes your starting point for game development. ޱ(ఠ皿ఠ)ว

(If you enjoyed it, a 👍 would be greatly appreciated!)

Back to Blog

Related posts

Read more »