dm 7 years ago
parent
commit
0cde8731b1

+ 44 - 23
examples/SoundDemo/src/TestCoord.h

@@ -8,46 +8,67 @@ class TestCoord: public Test
 {
 public:
 
-    spSprite orange;
+    spColorRectSprite sprite;
     spSoundInstance snd;
 
     TestCoord()
     {
-        orange = new ColorRectSprite;
-        orange->setColor(Color::Orange);
-        orange->setSize(getSize() - Vector2(100, 100));
-        orange->setPosition(getSize() / 2 - orange->getSize() / 2);
+        _content->addEventListener(TouchEvent::TOUCH_DOWN, CLOSURE(this, &TestCoord::onEvent));
+        _content->addEventListener(TouchEvent::TOUCH_UP, CLOSURE(this, &TestCoord::onEvent));
+        _content->addEventListener(TouchEvent::MOVE, CLOSURE(this, &TestCoord::onEvent));
+    }
 
-        orange->addEventListener(TouchEvent::OVER, CLOSURE(this, &TestCoord::onEvent));
-        orange->addEventListener(TouchEvent::MOVE, CLOSURE(this, &TestCoord::onEvent));
-        orange->addEventListener(TouchEvent::OUTX, CLOSURE(this, &TestCoord::onEvent));
+    ~TestCoord()
+    {
 
-        orange->setTouchChildrenEnabled(false);
-        orange->attachTo(_content);
     }
 
     void onEvent(Event* ev)
     {
         TouchEvent* te = safeCast<TouchEvent*>(ev);
 
-        if (ev->type == TouchEvent::OVER)
-        {
-            orange->setColor(Color::Green);
-            snd = splayer.play("amb_bird_2", PlayOptions().loop());
-        }
-        else if (ev->type == TouchEvent::OUTX)
+
+        Vector2 center = _content->getSize() / 2;
+        Vector2 dir = te->localPosition - center;
+        Vector3 pos3d = Vector3(dir.x, dir.y, 0) / 1000.0f;
+
+
+
+        if (ev->type == TouchEvent::TOUCH_DOWN)
         {
-            orange->setColor(Color::Orange);
-            snd->stop();
+            spColorRectSprite spr;
+            spr = new ColorRectSprite;
+            spr->setSize(20, 20);
+            spr->attachTo(_content);
+            spr->setTouchEnabled(false);
+            spr->setAnchor(0.5f, 0.5f);
+            spr->setPosition(te->localPosition);
+            sprite = spr;
+
+            snd = splayer.play("amb_bird_2", PlayOptions().loop().position3d(pos3d));
 
+#ifdef OX_HAS_CPP11
+            snd->setDoneCallback([spr](Event*)
+            {
+                spr->detach();
+            });
+#endif
         }
-        else     // TouchEvent::MOVE
-        {
 
-            Vector2 const center = orange->getSize() / 2;
-            Vector2 const dir    = te->localPosition - center;
+        if (!snd)
+            return;
 
-            snd->setPosition3D(Vector3(dir.x, dir.y, 0) / 1000.0f);
+        if (ev->type == TouchEvent::TOUCH_UP)
+        {
+            snd->setLoop(false);
+            sprite = 0;
+            snd = 0;
+        }
+
+        if (ev->type == TouchEvent::MOVE)
+        {
+            snd->setPosition3D(pos3d);
+            sprite->setPosition(te->localPosition);
         }
     }
 };

File diff suppressed because it is too large
+ 0 - 0
examples/SoundDemo/src/test.cpp


+ 4 - 4
examples/SoundDemo/src/test.h

@@ -36,8 +36,8 @@ public:
     void updateText(string id, string txt);
     virtual void clicked(string id) {}
     virtual void toggleClicked(string id, const toggle* data) {}
-    
-        
+
+
     void notify(string text, int time = 400);
 
 protected:
@@ -53,8 +53,8 @@ protected:
     spActor _ui;
 
     float _x;
-    float _y;    
-    
+    float _y;
+
     enum {MAX_NOTIFIES = 8};
     int _notifies[MAX_NOTIFIES];
 };

+ 2 - 2
src/sound/SoundHandle.h

@@ -24,7 +24,7 @@ namespace oxygine
         void setPitch(float pitch) { _pitch = pitch; _updatePitch(); }
         void setLoop(bool loop) { _looping = loop; _updateLoop(); }
         void setPosition(timeMS pos) { _setPosition(pos); }
-        void setPosition3D(const Vector3 &pos) { _pos3d = pos; _updatePosition3D(); }
+        void setPosition3D(const Vector3& pos) { _pos3d = pos; _updatePosition3D(); }
 
         float           getVolume() const { return _volume; }
         float           getPitch() const { return _pitch; }
@@ -55,7 +55,7 @@ namespace oxygine
         virtual void _pause() {}
         virtual void _resume() {}
         virtual void _stop() {}
-        virtual void _setPosition(int tm) {}        
+        virtual void _setPosition(int tm) {}
 
         virtual timeMS _getPosition() const = 0;
 

+ 2 - 2
src/sound/SoundInstance.cpp

@@ -299,7 +299,7 @@ namespace oxygine
         _volume = v;
         _updateVolume();
     }
-    
+
     void SoundInstance::setPitch(float v)
     {
         _handle->setPitch(v);
@@ -315,7 +315,7 @@ namespace oxygine
         _handle->setPosition(tm);
     }
 
-    void SoundInstance::setPosition3D(const Vector3 &pos)
+    void SoundInstance::setPosition3D(const Vector3& pos)
     {
         _handle->setPosition3D(pos);
     }

+ 1 - 1
src/sound/SoundInstance.h

@@ -73,7 +73,7 @@ namespace oxygine
         void    setPitch(float v);
         void    setLoop(bool loop);
         void    seek(int tm);
-        void    setPosition3D(const Vector3 &);
+        void    setPosition3D(const Vector3&);
 
         /**called when sound done*/
         void    setDoneCallback(EventCallback cb) {_cbDone = cb;}

+ 2 - 2
src/sound/SoundPlayer.h

@@ -19,7 +19,7 @@ namespace oxygine
     class PlayOptions
     {
     public:
-        PlayOptions() : _looped(false), _pitch(1.0f), _fadeIn(0), _fadeOut(0), _paused(false), _volume(-1.0f), _seek(0), _position3D(0,0,0){}
+        PlayOptions() : _looped(false), _pitch(1.0f), _fadeIn(0), _fadeOut(0), _paused(false), _volume(-1.0f), _seek(0), _position3D(0, 0, 0) {}
 
         PlayOptions& loop(bool loop = true) { _looped = loop; return *this; }
         PlayOptions& pitch(float v)  { _pitch = v; return *this; }
@@ -27,7 +27,7 @@ namespace oxygine
         PlayOptions& fade(timeMS fadeIn, timeMS fadeOut = 0) { _fadeIn = fadeIn; _fadeOut = fadeOut; return *this; }
         PlayOptions& pause() { _paused = true; return *this; }
         PlayOptions& seek(timeMS ms) { _seek = ms; return *this; }
-        PlayOptions& position3d(const Vector3 &pos) { _position3D = pos; return *this; }
+        PlayOptions& position3d(const Vector3& pos) { _position3D = pos; return *this; }
 
 
         float _pitch;

+ 1 - 1
src/sound/oal/SoundHandleOAL.cpp

@@ -140,7 +140,7 @@ namespace oxygine
     {
         if (!_alSource)
             return;
-        
+
         alSource3f(_alSource, AL_POSITION, _pos3d.x, _pos3d.y, _pos3d.z);
     }
 

Some files were not shown because too many files changed in this diff