Josh Engebretson 11 years ago
parent
commit
fdc2c8e991

+ 2 - 3
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -10,6 +10,7 @@ var sprite = node.createComponent("AnimatedSprite2D");
 sprite.setAnimation(animationSet, "Idle");
 sprite.setLayer(100);
 
+
 node.setPosition([8, 14, 0]);
 node.scale2D = [.25, .25];
 
@@ -23,7 +24,7 @@ circle.setRadius(2);
 // Set density
 circle.setDensity(1.0);
 // Set friction.
-circle.setFriction(1);
+circle.setFriction(.1);
 // Set restitution
 circle.setRestitution(0.1);
 
@@ -36,7 +37,6 @@ self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
     if (nodeB == node)
     {
-        print("contact: ", contactCount);
         contactCount++;
     }
     
@@ -47,7 +47,6 @@ self.onPhysicsEndContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
     if (nodeB == node)
     {
-        print("end contact: ", contactCount);
         contactCount--;
     }
 }

+ 42 - 1
PhysicsPlatformer/Resources/Components/Level.js

@@ -4,8 +4,49 @@ var tmxFile = cache.getResource("TmxFile2D", "Levels/Level1.tmx");
 
 var tileMapNode = scene.createChild("TileMap");
 tileMapNode.setPosition([0.0, 0.0, 0.0]);
+
 var tileMap = tileMapNode.createComponent("TileMap2D");
 tileMap.setTmxFile(tmxFile);
 
+physicsLayer = tileMap.getLayerByName("Physics");
+
+if (physicsLayer) {
+
+    for (var i = 0; i < physicsLayer.numObjects; i++) {
+    
+        var o = physicsLayer.getObject(i);
+
+        var onode = physicsLayer.getObjectNode(i);
+        var group = tmxFile.getTileObjectGroup(o.tileGid);
+        var obody = null;
+
+        if (group) {
+        
+            for (var j = 0; j < group.numObjects; j++) {
+
+                var go = group.getObject(j);
+
+                if (go.validCollisionShape()) {
+
+                    if (!obody) {
+                        obody = onode.createComponent("RigidBody2D");
+                        obody.bodyType = Atomic.BT_DYNAMIC;
+                        obody.awake = false;
+
+                    }
+
+                    var shape = go.createCollisionShape(onode);
+                    shape.density = 1.0;
+                    shape.friction = .5;
+                    shape.restitution = .1;
+
+                }
+            }
+        }
+    }
+}
+
+
+
 cameraNode.setPosition([8, 12, 0]);
-camera.setZoom(1.0);
+camera.setZoom(.75);