瀏覽代碼

Light2D stuff

Josh Engebretson 11 年之前
父節點
當前提交
4245db4d5d

+ 13 - 4
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -13,6 +13,14 @@ var sprite = node.createComponent("AnimatedSprite2D");
 sprite.setAnimation(animationSet, "Idle");
 sprite.setLayer(100);
 
+
+var light = node.createComponent("PointLight2D");
+light.color = [1, 1, 1, 1];
+light.softShadowLength = 4;
+light.radius = 4;
+
+lightGroup.addLight(light);
+
 camera.zoom = .9;
 
 node.setPosition(PlayerSpawnPoint);
@@ -124,8 +132,8 @@ function handleInput(timeStep) {
 
     var vel = body.linearVelocity;
     var pos = node.position2D;
-    
-    jumpDelta  -= timeStep;
+
+    jumpDelta -= timeStep;
 
     if (Math.abs(vel[0]) > MAX_VELOCITY) {
         vel[0] = (vel[0] ? vel[0] < 0 ? -1 : 1 : 0) * MAX_VELOCITY;
@@ -161,11 +169,12 @@ function handleInput(timeStep) {
     if (zoomOut)
         camera.zoom -= timeStep;
 
-
+    /*
     if (camera.zoom > 1.5)
         camera.zoom = 1.5;
     if (camera.zoom < .75)
         camera.zoom = .75;
+     */
 
     if (left && vel[0] > -MAX_VELOCITY) {
         body.applyLinearImpulse([-2, 0], pos, true);
@@ -185,7 +194,7 @@ function handleInput(timeStep) {
         circle.friction = 0.0;
 
     if (jump && jumpDelta <= 0 && contactCount) {
-        
+
         jumpDelta = .25;
         self.soundSource.gain = 0.75;
         self.soundSource.play(jumpSound);

+ 8 - 0
PhysicsPlatformer/Resources/Components/Bat.js

@@ -15,6 +15,14 @@ node.scale2D = [.5, .5];
 
 var cwaypoint = -1;
 
+var light = node.createComponent("PointLight2D");
+light.color = [1, 1, 1, 1];
+light.softShadowLength = 4;
+light.radius = 4;
+
+lightGroup.addLight(light);
+
+
 function update(timestep) {
 
     var waypoints = TheLevel.batWaypoints;

+ 7 - 3
PhysicsPlatformer/Resources/PhysicsPlatformer.js

@@ -48,11 +48,16 @@ function CreateScene() {
     
     var viewport = new Atomic.Viewport(scene, camera);
     renderer.setViewport(0, viewport);
+
+    // currently lightgroup must be created after viewport 0 is set
+    lightGroupNode = scene.createChild("LightGroup");
+    lightGroup = lightGroupNode.createComponent("Light2DGroup");
+    lightGroup.setPhysicsWorld(physicsWorld);
+        
     
     uiNode = scene.createChild("UI");
     uiNode.createJSComponent("UI");
-
-    
+ 
     levelNode = scene.createChild("Level");
     levelNode.createJSComponent("Level");
     avatarNode = scene.createChild("Avatar");
@@ -60,7 +65,6 @@ function CreateScene() {
     backgroundNode = scene.createChild("Background");
     backgroundNode .createJSComponent("Background");       
     
-
     
 
 }