Browse Source

Merge remote-tracking branch '1vanK/master'

Lasse Öörni 10 years ago
parent
commit
cc3aaddb57
2 changed files with 16 additions and 3 deletions
  1. 5 3
      Source/Urho3D/Urho2D/CollisionShape2D.cpp
  2. 11 0
      Source/Urho3D/Urho2D/RigidBody2D.cpp

+ 5 - 3
Source/Urho3D/Urho2D/CollisionShape2D.cpp

@@ -212,7 +212,11 @@ void CollisionShape2D::CreateFixture()
         return;
 
     if (!rigidBody_)
-        return;
+    {
+        rigidBody_ = node_->GetComponent<RigidBody2D>(); // RigidBody2D can be created after CollisionShape2D
+        if (!rigidBody_)
+            return;
+    }
 
     b2Body* body = rigidBody_->GetBody();
     if (!body)
@@ -284,8 +288,6 @@ void CollisionShape2D::OnNodeSet(Node* node)
             CreateFixture();
             rigidBody_->AddCollisionShape2D(this);
         }
-        else
-            LOGERROR("No right body component in node, can not create collision shape");
     }
 }
 

+ 11 - 0
Source/Urho3D/Urho2D/RigidBody2D.cpp

@@ -475,7 +475,18 @@ float RigidBody2D::GetAngularVelocity() const
 void RigidBody2D::OnNodeSet(Node* node)
 {
     if (node)
+    {
         node->AddListener(this);
+
+        PODVector<CollisionShape2D*> shapes;
+        node_->GetDerivedComponents<CollisionShape2D>(shapes);
+
+        for (PODVector<CollisionShape2D*>::Iterator i = shapes.Begin(); i != shapes.End(); ++i)
+        {
+            (*i)->CreateFixture();
+            AddCollisionShape2D(*i);
+        }
+    }
 }
 
 void RigidBody2D::OnSceneSet(Scene* scene)