Main > Getting Started > Playing Sound

Tiny2D supports WAV, MP3, OGG and multiple other audio formats.

Below sample plays one sound effect every 3 seconds and it
plays looped music indefinitely.

#include "Tiny2D.h"

using namespace Tiny2D;

class SoundApp : public App::Callbacks
{
public:
	virtual bool OnInit()
	{
		sound.Create("my_sound.wav");
		timer = 0.0f;

		music.Create("my_music.ogg", true /* is music */);
		music.Play(true /* loop */);

		return true;
	}
	
	virtual void OnUpdate(float deltaTime)
	{
		timer -= deltaTime;
		if (timer <= 0.0f)
		{
			timer = 3.0f;
			sound.Play();
		}
	}

private:
	Sound sound;
	Sound music;
	float timer;
};

TINY2D_DEFINE_APP(SoundApp);





Contact: contact at pixelelephant dot com
(C) 2013 Pixel Elephant - All Rights Reserved