basic interfacing of sfml sound/music and integration with scenenode
This commit is contained in:
parent
e5a9ac9da0
commit
73eb0d20ab
28
src/scene/musicnode.cpp
Normal file
28
src/scene/musicnode.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "musicnode.h"
|
||||||
|
|
||||||
|
MusicNode::MusicNode(std::string musicFileName):
|
||||||
|
m_music_file(musicFileName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicNode::init(){
|
||||||
|
m_valid = m_music.openFromFile(m_music_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicNode::play()
|
||||||
|
{
|
||||||
|
if (m_valid)
|
||||||
|
m_music.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicNode::pause()
|
||||||
|
{
|
||||||
|
if(m_valid)
|
||||||
|
m_music.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicNode::stop()
|
||||||
|
{
|
||||||
|
if(m_valid)
|
||||||
|
m_music.stop();
|
||||||
|
}
|
22
src/scene/musicnode.h
Normal file
22
src/scene/musicnode.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef MUSICNODE_H
|
||||||
|
#define MUSICNODE_H
|
||||||
|
|
||||||
|
#include "scenenode.h"
|
||||||
|
#include "SFML/Audio.hpp"
|
||||||
|
|
||||||
|
class MusicNode : public SceneNode
|
||||||
|
{
|
||||||
|
sf::Music m_music;
|
||||||
|
std::string m_music_file;
|
||||||
|
bool m_valid;
|
||||||
|
public:
|
||||||
|
MusicNode(std::string musicFileName);
|
||||||
|
void init();
|
||||||
|
void play();
|
||||||
|
void pause();
|
||||||
|
void stop();
|
||||||
|
void setPlayingOffset(int offset);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MUSICNODE_H
|
40
src/scene/soundnode.cpp
Normal file
40
src/scene/soundnode.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "soundnode.h"
|
||||||
|
#include "resourcemanager.h"
|
||||||
|
|
||||||
|
SoundNode::SoundNode(std::string soundFileName):
|
||||||
|
m_sound_file(soundFileName)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundNode::init()
|
||||||
|
{
|
||||||
|
if ((m_valid = RESOURCE_CHECK(sf::SoundBuffer,m_sound_file)))
|
||||||
|
m_sound.setBuffer(*RESOURCE_GET(sf::SoundBuffer, m_sound_file));
|
||||||
|
else{
|
||||||
|
sf::SoundBuffer* buffer;
|
||||||
|
m_valid = buffer->loadFromFile(m_sound_file);
|
||||||
|
if(m_valid){
|
||||||
|
RESOURCE_ADD(buffer,sf::SoundBuffer,m_sound_file);
|
||||||
|
m_sound.setBuffer(*buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundNode::play()
|
||||||
|
{
|
||||||
|
if (m_valid)
|
||||||
|
m_sound.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundNode::pause()
|
||||||
|
{
|
||||||
|
if(m_valid)
|
||||||
|
m_sound.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoundNode::stop()
|
||||||
|
{
|
||||||
|
if(m_valid)
|
||||||
|
m_sound.stop();
|
||||||
|
}
|
20
src/scene/soundnode.h
Normal file
20
src/scene/soundnode.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef SOUNDNODE_H
|
||||||
|
#define SOUNDNODE_H
|
||||||
|
|
||||||
|
#include "scene/scenenode.h"
|
||||||
|
#include "SFML/Audio.hpp"
|
||||||
|
|
||||||
|
class SoundNode : public SceneNode
|
||||||
|
{
|
||||||
|
sf::Sound m_sound;
|
||||||
|
std::string m_sound_file;
|
||||||
|
bool m_valid;
|
||||||
|
public:
|
||||||
|
SoundNode(std::string soundFileName);
|
||||||
|
void init();
|
||||||
|
void play();
|
||||||
|
void pause();
|
||||||
|
void stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SOUNDNODE_H
|
@ -85,6 +85,7 @@ public:
|
|||||||
|
|
||||||
unsigned int getIndex(){return m_buffer->getIndex();}
|
unsigned int getIndex(){return m_buffer->getIndex();}
|
||||||
ShellBuffer* getBuffer(){return m_buffer;}
|
ShellBuffer* getBuffer(){return m_buffer;}
|
||||||
|
ScriptNode* getScript(){return m_script;}
|
||||||
|
|
||||||
void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);
|
void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user