Browse Source

click sound

dmuratshin 9 years ago
parent
commit
10e1ad8a1f

BIN
my_awesome_game/data/sounds/bomb_match.ogg


BIN
my_awesome_game/data/sounds/button_click.ogg


+ 1 - 0
my_awesome_game/project/src/MyButton.cpp

@@ -23,6 +23,7 @@ void MyButton::onEvent(Event* ev)
         //clicked button should scale up and down
         //clicked button should scale up and down
         setScale(1.0f);
         setScale(1.0f);
         addTween(Actor::TweenScale(1.1f), 300, 1, true);
         addTween(Actor::TweenScale(1.1f), 300, 1, true);
+        playSound("click");
     }
     }
 }
 }
 
 

+ 7 - 5
my_awesome_game/project/src/example.cpp

@@ -1,20 +1,22 @@
 #include "oxygine-framework.h"
 #include "oxygine-framework.h"
+#include "oxygine-sound.h"
 #include "res.h"
 #include "res.h"
 #include "Game.h"
 #include "Game.h"
 #include "MainMenuScene.h"
 #include "MainMenuScene.h"
 #include "GameScene.h"
 #include "GameScene.h"
 #include "GameMenu.h"
 #include "GameMenu.h"
-#include "SoundSystem.h"
 using namespace oxygine;
 using namespace oxygine;
 
 
 
 
+SoundPlayer player;
+
 void example_preinit()
 void example_preinit()
 {
 {
 }
 }
 
 
 void example_init()
 void example_init()
 {
 {
-	SoundSystem::create()->init(16);
+    SoundSystem::create()->init(16);
     //load resources
     //load resources
     res::load();
     res::load();
 
 
@@ -29,8 +31,8 @@ void example_init()
 
 
 void example_update()
 void example_update()
 {
 {
-	SoundSystem::get()->update();
-
+    SoundSystem::get()->update();
+    player.update();
 }
 }
 
 
 void example_destroy()
 void example_destroy()
@@ -41,5 +43,5 @@ void example_destroy()
 
 
     res::free();
     res::free();
 
 
-	SoundSystem::free();
+    SoundSystem::free();
 }
 }

+ 2 - 0
my_awesome_game/project/src/example.h

@@ -1,3 +1,5 @@
+#pragma once
+
 void example_preinit();
 void example_preinit();
 void example_init();
 void example_init();
 void example_destroy();
 void example_destroy();

+ 12 - 0
my_awesome_game/project/src/res.cpp

@@ -1,17 +1,29 @@
 #include "res.h"
 #include "res.h"
+#include "oxygine-sound.h"
+
+extern  SoundPlayer player;
 
 
 namespace res
 namespace res
 {
 {
     Resources ui;
     Resources ui;
+    unordered_map<string, ResSound*> sounds;
 
 
     void load()
     void load()
     {
     {
         ui.loadXML("xmls/ui.xml");
         ui.loadXML("xmls/ui.xml");
+        sounds["click"] = ResSound::create("sounds/button_click.ogg", false);
     }
     }
 
 
     void free()
     void free()
     {
     {
         ui.free();
         ui.free();
 
 
+        delete sounds["click"];
     }
     }
+}
+
+
+void playSound(const string& id)
+{
+    player.play(res::sounds[id]);
 }
 }

+ 8 - 1
my_awesome_game/project/src/res.h

@@ -1,10 +1,17 @@
 #pragma once
 #pragma once
 #include "oxygine-framework.h"
 #include "oxygine-framework.h"
+#include <unordered_map>
+#include "ResSound.h"
+
 using namespace oxygine;
 using namespace oxygine;
+using namespace std;
 
 
 namespace res
 namespace res
 {
 {
     extern Resources ui;
     extern Resources ui;
     void load();
     void load();
     void free();
     void free();
-}
+}
+
+
+void playSound(const string& id);

+ 1 - 1
oxygine-sound

@@ -1 +1 @@
-Subproject commit b6af1870a2671e238e637ce06291ed405698d52e
+Subproject commit 39b13deeabe6fe2f5aaa338fb60ffc364f302a54