rsredsq пре 10 година
родитељ
комит
5a9a676e01

+ 7 - 6
Light2DExample/Resources/Components/Background.js

@@ -1,23 +1,24 @@
 'atomic component';
 'atomic component';
 
 
+//A Background component
 exports.component = function(self) {
 exports.component = function(self) {
-
+    //Link to the current node
     var node = self.node;
     var node = self.node;
-
+    //Get main camera of the current scene
     var camera = node.scene.getMainCamera();
     var camera = node.scene.getMainCamera();
+    //set its ortho size
     camera.orthoSize = Atomic.graphics.height * Atomic.PIXEL_SIZE;
     camera.orthoSize = Atomic.graphics.height * Atomic.PIXEL_SIZE;
 
 
+    //Get StaticSprite2D component from the current node
     var sprite2D = node.getComponent("StaticSprite2D");
     var sprite2D = node.getComponent("StaticSprite2D");
 
 
-    console.log(sprite2D);
-
     var width = sprite2D.sprite.texture.width;
     var width = sprite2D.sprite.texture.width;
     var height = sprite2D.sprite.texture.height;
     var height = sprite2D.sprite.texture.height;
 
 
     var viewWidth = Atomic.graphics.width;
     var viewWidth = Atomic.graphics.width;
     var viewHeight = Atomic.graphics.height;
     var viewHeight = Atomic.graphics.height;
 
 
+    //scale the current node with X and Y
     node.scale2D = [viewWidth / width, viewHeight / height];
     node.scale2D = [viewWidth / width, viewHeight / height];
 
 
-
-}
+}

+ 6 - 5
Light2DExample/Resources/Components/Light.js

@@ -3,26 +3,28 @@
 var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
 var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
 var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
 var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
 
 
+//Light component
 exports.component = function(self) {
 exports.component = function(self) {
-
+    //Link to the current node
     var node = self.node;
     var node = self.node;
+    //Get PointLight2D component and set its color
     var light = node.getComponent("PointLight2D");
     var light = node.getComponent("PointLight2D");
-
     light.color = [.1 + Math.random() * .9, .1 + Math.random() * .9, .1 + Math.random() * .9, 1];
     light.color = [.1 + Math.random() * .9, .1 + Math.random() * .9, .1 + Math.random() * .9, 1];
 
 
     var x = -halfWidth + (halfWidth * 2) * Math.random();
     var x = -halfWidth + (halfWidth * 2) * Math.random();
     var y = -halfHeight + (halfHeight * 2) * Math.random();
     var y = -halfHeight + (halfHeight * 2) * Math.random();
 
 
+    //Set position of the current node in the 2D space
     node.position2D = [x, y];
     node.position2D = [x, y];
 
 
     var movex = -2 + (Math.random() * 4);
     var movex = -2 + (Math.random() * 4);
     var movey = -2 + (Math.random() * 4);
     var movey = -2 + (Math.random() * 4);
 
 
-    // Update
+    // Update function calls one per each frame
     self.update = function(timeStep) {
     self.update = function(timeStep) {
 
 
         var prev = node.position2D;
         var prev = node.position2D;
-
+        //translate node in 2D space on X and Y values
         node.translate2D([movex * timeStep, movey * timeStep]);
         node.translate2D([movex * timeStep, movey * timeStep]);
 
 
         var p = node.position2D;
         var p = node.position2D;
@@ -40,4 +42,3 @@ exports.component = function(self) {
     }
     }
 
 
 }
 }
-

+ 7 - 27
Light2DExample/Resources/Components/ShadowCaster.js

@@ -3,19 +3,23 @@
 var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
 var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
 var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
 var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
 
 
+//ShadowCaster component
 exports.component = function(self) {
 exports.component = function(self) {
-
+    //Link to the current node
     var node = self.node;
     var node = self.node;
 
 
+    //Create RigidBody2D component on the current node and make its static and cast shadows
     var body = node.createComponent("RigidBody2D");
     var body = node.createComponent("RigidBody2D");
     body.bodyType = Atomic.BT_STATIC;
     body.bodyType = Atomic.BT_STATIC;
     body.castShadows = true;
     body.castShadows = true;
 
 
+    //Create circle collision and set its radius
     var circle = node.createComponent("CollisionCircle2D");
     var circle = node.createComponent("CollisionCircle2D");
     circle.radius = .35;
     circle.radius = .35;
 
 
-    var sprite2D = Atomic.cache.getResource("Sprite2D", "Sprites/ball" + (Math.round(Math.random() * 7) + 1) + ".png");
+    //Create sprite
     var sprite = node.createComponent("StaticSprite2D");
     var sprite = node.createComponent("StaticSprite2D");
+    var sprite2D = Atomic.cache.getResource("Sprite2D", "Sprites/ball" + (Math.round(Math.random() * 7) + 1) + ".png");
     sprite.setSprite(sprite2D);
     sprite.setSprite(sprite2D);
 
 
     var x = -halfWidth + (halfWidth * 2) * Math.random();
     var x = -halfWidth + (halfWidth * 2) * Math.random();
@@ -24,31 +28,7 @@ exports.component = function(self) {
     // tolerance towards the middle of screen
     // tolerance towards the middle of screen
     x *= .7;
     x *= .7;
     y *= .7;
     y *= .7;
-
+    //Set position of the current node in 2D space
     node.position2D = [x, y];
     node.position2D = [x, y];
 
 
-
-}
-
-/*
-var game = Atomic.game;
-var node = self.node;
-
-var body = node.createComponent("RigidBody2D");
-body.bodyType = Atomic.BT_STATIC;
-body.castShadows = true;
-
-var circle = node.createComponent("CollisionCircle2D");
-circle.radius = .35;
-
-
-function start() {
-
-
-}
-
-function update(timeStep) {
-
-
 }
 }
-*/

+ 2 - 10
Light2DExample/Resources/Scripts/main.js

@@ -1,11 +1,3 @@
 // This script is the main entry point of the game
 // This script is the main entry point of the game
-
-var scene = Atomic.player.loadScene("Scenes/Scene.scene");
-
-// called per frame, optional
-function update(timeStep) {
-
-
-}
-
-exports.update = update;
+//Load scene
+Atomic.player.loadScene("Scenes/Scene.scene");