dmuratshin 9 gadi atpakaļ
vecāks
revīzija
10f48dcb70
2 mainītis faili ar 30 papildinājumiem un 3 dzēšanām
  1. 27 3
      oxygine/src/DebugActor.cpp
  2. 3 0
      oxygine/src/DebugActor.h

+ 27 - 3
oxygine/src/DebugActor.cpp

@@ -134,7 +134,7 @@ namespace oxygine
         btn->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DebugActor::_btnClicked));
         btn->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DebugActor::_btnClicked));
     }
     }
 
 
-    DebugActor::DebugActor(): _frames(0), _startTime(0), _showTexel2PixelErrors(false), _showTouchedActor(false)
+    DebugActor::DebugActor(): _frames(0), _startTime(0), _showTexel2PixelErrors(false), _showTouchedActor(false), _dragging(false)
     {
     {
         DebugActor::initialize();
         DebugActor::initialize();
 
 
@@ -208,7 +208,10 @@ namespace oxygine
 
 
     void DebugActor::onAdded2Stage()
     void DebugActor::onAdded2Stage()
     {
     {
+        _dragging = false;
         _stage->addEventListener(TouchEvent::MOVE, CLOSURE(this, &DebugActor::onDAEvent));
         _stage->addEventListener(TouchEvent::MOVE, CLOSURE(this, &DebugActor::onDAEvent));
+        _stage->addEventListener(TouchEvent::TOUCH_DOWN, CLOSURE(this, &DebugActor::onDAEvent));
+        _stage->addEventListener(TouchEvent::TOUCH_UP, CLOSURE(this, &DebugActor::onDAEvent));
     }
     }
 
 
     void DebugActor::onRemovedFromStage()
     void DebugActor::onRemovedFromStage()
@@ -417,7 +420,7 @@ namespace oxygine
                 break;
                 break;
         }
         }
 
 
-        setPosition(pos);
+        //setPosition(pos);
         setScale(1.0f / getStage()->getScaleX());
         setScale(1.0f / getStage()->getScaleX());
 
 
 
 
@@ -478,7 +481,28 @@ namespace oxygine
     {
     {
         TouchEvent* t = safeCast<TouchEvent*>(ev);
         TouchEvent* t = safeCast<TouchEvent*>(ev);
         Vector2 loc = stage2local(t->localPosition, _getStage());
         Vector2 loc = stage2local(t->localPosition, _getStage());
-        setAlpha(isOn(loc) ? 64 : 255);
+        if (t->type == TouchEvent::MOVE)
+        {
+            setAlpha(isOn(loc) ? 64 : 255);
+
+            if (_dragging)
+            {
+                setPosition(t->localPosition - _local);
+            }
+        }
+
+        if (t->type == TouchEvent::TOUCH_DOWN)
+        {
+            if (isOn(loc))
+            {
+                _local = loc;
+                _dragging = true;
+            }
+        }
+        if (t->type == TouchEvent::TOUCH_UP)
+        {
+            _dragging = false;
+        }
     }
     }
 
 
     void DebugActor::onEvent(Event* ev)
     void DebugActor::onEvent(Event* ev)

+ 3 - 0
oxygine/src/DebugActor.h

@@ -63,6 +63,9 @@ namespace oxygine
         bool _showTouchedActor;
         bool _showTouchedActor;
         bool _showTexel2PixelErrors;
         bool _showTexel2PixelErrors;
 
 
+        bool _dragging;
+        Vector2 _local;
+
         void onEvent(Event* ev);
         void onEvent(Event* ev);
         void onDAEvent(Event* ev);
         void onDAEvent(Event* ev);
     };
     };