Explorar o código

Fix touch emulation in 32_Physics2DConstraints

1vanK %!s(int64=3) %!d(string=hai) anos
pai
achega
45659da228

+ 6 - 2
Source/Samples/32_Physics2DConstraints/Urho2DConstraints.cpp

@@ -454,8 +454,8 @@ void Urho2DConstraints::SubscribeToEvents()
     // Unsubscribe the SceneUpdate event from base class to prevent camera pitch and yaw in 2D sample
     UnsubscribeFromEvent(E_SCENEUPDATE);
 
-    if (touchEnabled_)
-        SubscribeToEvent(E_TOUCHBEGIN, URHO3D_HANDLER(Urho2DConstraints, HandleTouchBegin3));
+    // Overwrite the subscription from the base class
+    SubscribeToEvent(E_TOUCHBEGIN, URHO3D_HANDLER(Urho2DConstraints, HandleTouchBegin3));
 }
 
 void Urho2DConstraints::HandleUpdate(StringHash eventType, VariantMap& eventData)
@@ -546,6 +546,10 @@ void Urho2DConstraints::HandleMouseMove(StringHash eventType, VariantMap& eventD
 
 void Urho2DConstraints::HandleTouchBegin3(StringHash eventType, VariantMap& eventData)
 {
+    // On some platforms like Windows the presence of touch input can only be detected dynamically
+    if (!touchEnabled_)
+        InitTouchInput();
+
     auto* graphics = GetSubsystem<Graphics>();
     auto* physicsWorld = scene_->GetComponent<PhysicsWorld2D>();
     using namespace TouchBegin;