Browse Source

Commented CharacterAnimation2D, CharacterAnimation3D, EventLoop, Particles2D, RenderToTexture, UISceneView2D

rsredsq 10 years ago
parent
commit
7592fab9e4

+ 4 - 2
CharacterAnimation2D/Resources/Components/Imp.js

@@ -1,11 +1,13 @@
 'atomic component';
 
+//Imp component
 exports.component = function(self) {
-
+    //Link to the current node
     var node = self.node;
 
     var animatedSprite = node.getComponent("AnimatedSprite2D");
 
+    //Listen events and set animation
     self.subscribeToEvent("PlayRun", function() {
         animatedSprite.setAnimation("run");
     });
@@ -26,4 +28,4 @@ exports.component = function(self) {
         animatedSprite.setAnimation("dead");
     });
 
-}
+}

+ 12 - 9
CharacterAnimation2D/Resources/Components/UI.js

@@ -1,41 +1,44 @@
 'atomic component';
 
+//define font description style
 var fd = new Atomic.UIFontDescription();
 fd.id = "Vera";
 fd.size = 22;
 
 function createButton(self, text, event, layout) {
-
+    //create UIButton element
     var button = new Atomic.UIButton();
+    //set its text and font description style
     button.text = text;
     button.fontDescription = fd;
-
+    //laying on the right side
     button.gravity = Atomic.UI_GRAVITY_RIGHT;
-
+    //this event will be called when buttons is clicked
     button.onClick = function() {
 
         self.sendEvent(event);
 
     }
-
+    //add button
     layout.addChild(button);
 
 }
-
+//UI component
 exports.component = function(self) {
-  
+
     // root view
     self.uiView = new Atomic.UIView();
-
+    // Create a layout, otherwise child widgets won't know how to size themselves
+    // and would manually need to be sized
     var layout = new Atomic.UILayout();
     layout.rect = self.uiView.rect;
 
     layout.axis = Atomic.UI_AXIS_Y;
 
     layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_GRAVITY;
-
+    //add our layout
     self.uiView.addChild(layout);
-
+    //create buttons
     createButton(self, "Play Idle", "PlayIdle", layout);
     createButton(self, "Play Run", "PlayRun", layout);
     createButton(self, "Play Attack", "PlayAttack", layout);

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

@@ -1,11 +1,3 @@
 // 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");

+ 6 - 6
CharacterAnimation3D/Resources/Components/Roboman.js

@@ -1,13 +1,13 @@
 'atomic component';
-
+//Roboman component
 exports.component = function(self) {
-
+    //link to the current node
     var node = self.node;
-
+    //get aniomatio controller component
     var animationController = node.getComponent("AnimationController");
 
     animationController.playExclusive("Idle", 0, true);
-
+    //Listen events and play animation
     self.subscribeToEvent("PlayRun", function() {
         animationController.playExclusive("Run", 0, true);
     });
@@ -26,9 +26,9 @@ exports.component = function(self) {
 
 
     self.update = function(timeStep) {
-        
+        //rotate ours node around Y axis
         node.yaw(timeStep * 10);
 
     }
 
-}
+}

+ 11 - 8
CharacterAnimation3D/Resources/Components/UI.js

@@ -1,39 +1,42 @@
 'atomic component';
 
+//define font description style
 var fd = new Atomic.UIFontDescription();
 fd.id = "Vera";
 fd.size = 22;
 
 function createButton(self, text, event, layout) {
-
+    //create UIButton element
     var button = new Atomic.UIButton();
+    //set its text and font description style
     button.text = text;
     button.fontDescription = fd;
-
+    //laying on the right side
     button.gravity = Atomic.UI_GRAVITY_RIGHT;
-
+    //this event will be called when buttons is clicked
     button.onClick = function() {
 
         self.sendEvent(event);
 
     }
-
+    //add button
     layout.addChild(button);
 
 }
-
+//UI component
 exports.component = function(self) {
 
-    // root view
+    // create a root view
     self.uiView = new Atomic.UIView();
-
+    // Create a layout, otherwise child widgets won't know how to size themselves
+    // and would manually need to be sized
     var layout = new Atomic.UILayout();
     layout.rect = self.uiView.rect;
 
     layout.axis = Atomic.UI_AXIS_Y;
 
     layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_GRAVITY;
-
+    //add layout to the root view
     self.uiView.addChild(layout);
 
     createButton(self, "Play Idle", "PlayIdle", layout);

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

@@ -1,11 +1,3 @@
 // 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");

+ 2 - 1
EventLoop/Resources/Components/Star.js

@@ -6,11 +6,12 @@ module.exports.component = function (self) {
     var inspectorFields = {
         speed: 100,
     };
-
+    //link to the current node
     var node = self.node;
 
     // Start will be called when component is instantiated
     self.start = function () {
+        //create a new sprite
         var sprite2D = node.createComponent("StaticSprite2D");
         sprite2D.sprite = Atomic.cache.getResource("Sprite2D", "Sprites/star.png");
         sprite2D.blendMode = Atomic.BLEND_ALPHA;

+ 6 - 8
EventLoop/Resources/Scripts/main.js

@@ -10,17 +10,15 @@ function createScene() {
     // create a 2D scene
     var scene = new Atomic.Scene();
     scene.createComponent("Octree");
-
+    //craete camera node
     var cameraNode = scene.createChild("Camera");
     cameraNode.position = [0.0, 0.0, -10.0];
-
+    //create camera component, and set it to ortho
     var camera = cameraNode.createComponent("Camera");
     camera.orthographic = true;
     camera.orthoSize = Atomic.graphics.height * Atomic.PIXEL_SIZE;
-
-    var viewport = null;
-
-    viewport = new Atomic.Viewport(scene, camera);
+    //create a main viewport
+    var viewport = new Atomic.Viewport(scene, camera);
     Atomic.renderer.setViewport(0, viewport);
 
     return scene;
@@ -61,12 +59,12 @@ function main() {
                 setImmediate(function() {
                     star.speed = 1000;
                 });
-                
+
                 // set up something that we are going to immediately cancel so it doesn't happen
                 var wonthappen  = setImmediate(function() {
                     star.speed = 100;
                 });
-                
+
                 clearImmediate(wonthappen);
             }
         }, 5);

+ 5 - 5
Particles2D/Resources/Components/ParticleSystem.js

@@ -1,11 +1,11 @@
 'atomic component';
-
+//ParticleSystem component
 exports.component = function(self) {
-
+    //link to the current node
     var node = self.node;
-
+    //get emitter
     var emitter = node.getComponent("ParticleEmitter2D");
-
+    //listen to events and set an effect
     self.subscribeToEvent("PlayHearts", function() {
         emitter.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/love.pex");
     });
@@ -18,4 +18,4 @@ exports.component = function(self) {
         emitter.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/snow.pex");
     });
 
-}
+}

+ 12 - 9
Particles2D/Resources/Components/UI.js

@@ -1,41 +1,44 @@
 'atomic component';
 
+//define font description style
 var fd = new Atomic.UIFontDescription();
 fd.id = "Vera";
 fd.size = 22;
 
 function createButton(self, text, event, layout) {
-
+    //create UIButton element
     var button = new Atomic.UIButton();
+    //set its text and font description style
     button.text = text;
     button.fontDescription = fd;
-
+    //laying on the right side
     button.gravity = Atomic.UI_GRAVITY_RIGHT;
-
+    //this event will be called when buttons is clicked
     button.onClick = function() {
 
         self.sendEvent(event);
 
     }
-
+    //add button
     layout.addChild(button);
 
 }
-
+//UI component
 exports.component = function(self) {
-  
+
     // root view
     self.uiView = new Atomic.UIView();
-
+    // Create a layout, otherwise child widgets won't know how to size themselves
+    // and would manually need to be sized
     var layout = new Atomic.UILayout();
     layout.rect = self.uiView.rect;
 
     layout.axis = Atomic.UI_AXIS_Y;
 
     layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_GRAVITY;
-
+    //add our layout
     self.uiView.addChild(layout);
-
+    //create buttons
     createButton(self, "Play Hearts", "PlayHearts", layout);
     createButton(self, "Play Snow", "PlaySnow", layout);
     createButton(self, "Play Spark", "PlaySpark", layout);

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

@@ -1,11 +1,3 @@
 // 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");

+ 32 - 36
RenderToTexture/Resources/Components/RenderToTexture.js

@@ -1,44 +1,40 @@
 "atomic component";
-
-var component = function(self) {
-
-    var node = self.node;
-    var model = node.getComponent("StaticModel");
-
+//RenderToTexture component
+exports.component = function(self) {
+    //Load the current scene, but don't set it as main scene to the player
     var scene = Atomic.player.loadScene("Scenes/RenderToTextureScene.scene");
 
-    // Create a renderable texture (1024x1024, RGB format), enable bilinear filtering on it
-
-    var renderTexture = new Atomic.Texture2D();
-    renderTexture.setSize(1024, 1024, Atomic.graphics.getRGBFormat(), Atomic.TEXTURE_RENDERTARGET);
-    renderTexture.filterMode = Atomic.FILTER_BILINEAR;
-
-    // Create a new material from scratch, use the diffuse unlit technique, assign the render texture
-    // as its diffuse texture, then assign the material box object
-    var renderMaterial = new Atomic.Material();
-    renderMaterial.setTechnique(0, Atomic.cache.getResource("Technique", "Techniques/Diff.xml"));
-    renderMaterial.setTexture(Atomic.TU_DIFFUSE, renderTexture);
-    model.setMaterial(renderMaterial);
-
-    // Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)
-    // and define the viewport for rendering the second scene, similarly as how backbuffer viewports are defined
-    // to the Renderer subsystem. By default the texture viewport will be updated when the texture is visible
-    // in the main view
-
-    var cameras = scene.getComponents("Camera", true);
-
-    var surface = renderTexture.getRenderSurface();
-    var rttViewport = new Atomic.Viewport(scene, cameras[0]);
-    surface.setViewport(0, rttViewport);
-
     self.start = function() {
-
-    }
-
-    self.update = function(timeStep) {
+      //link to the current node
+      var node = self.node;
+
+      var model = node.getComponent("StaticModel");
+
+      // Create a renderable texture (1024x1024, RGB format), enable bilinear filtering on it
+      var renderTexture = new Atomic.Texture2D();
+      renderTexture.setSize(1024, 1024, Atomic.graphics.getRGBFormat(), Atomic.TEXTURE_RENDERTARGET);
+      renderTexture.filterMode = Atomic.FILTER_BILINEAR;
+
+      // Create a new material from scratch, use the diffuse unlit technique, assign the render texture
+      // as its diffuse texture, then assign the material box object
+      var renderMaterial = new Atomic.Material();
+      renderMaterial.setTechnique(0, Atomic.cache.getResource("Technique", "Techniques/Diff.xml"));
+      renderMaterial.setTexture(Atomic.TU_DIFFUSE, renderTexture);
+      model.setMaterial(renderMaterial);
+
+      // Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)
+      // and define the viewport for rendering the second scene, similarly as how backbuffer viewports are defined
+      // to the Renderer subsystem. By default the texture viewport will be updated when the texture is visible
+      // in the main view
+
+      var camera = scene.getComponents("Camera", true)[0];
+      //get surface of the render texture
+      var surface = renderTexture.getRenderSurface();
+      //create a new viewport
+      var rttViewport = new Atomic.Viewport(scene, camera);
+      //set rttViewport as a main viewport in the surface
+      surface.setViewport(0, rttViewport);
 
     }
 
 }
-
-exports.component = component;

+ 4 - 3
RenderToTexture/Resources/Components/Spinner.js

@@ -1,5 +1,5 @@
 "atomic component";
-
+//inspector fields to make speed variable visible in editor
 var inspectorFields = {
     speed: 1.0
 }
@@ -7,9 +7,10 @@ var inspectorFields = {
 exports.component = function(self) {
 
     self.update = function(timeStep) {
-
+        //rotate current node around Y axis
         self.node.yaw(timeStep * 75 * self.speed);
+        //rotate current node around X axis
         self.node.pitch(-timeStep * 25 * self.speed);
     }
 
-}
+}

+ 2 - 2
RenderToTexture/Resources/Scenes/MainScene.scene

@@ -5,8 +5,8 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="367" />
-	<attribute name="Next Replicated Component ID" value="1981" />
+	<attribute name="Next Replicated Node ID" value="369" />
+	<attribute name="Next Replicated Component ID" value="1983" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Variables" />

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

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

+ 4 - 4
ToonTown/Resources/Scenes/ToonTown.scene

@@ -5,10 +5,10 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="365" />
-	<attribute name="Next Replicated Component ID" value="1981" />
-	<attribute name="Next Local Node ID" value="16779264" />
-	<attribute name="Next Local Component ID" value="16777984" />
+	<attribute name="Next Replicated Node ID" value="366" />
+	<attribute name="Next Replicated Component ID" value="1982" />
+	<attribute name="Next Local Node ID" value="16779520" />
+	<attribute name="Next Local Component ID" value="16778240" />
 	<attribute name="Variables" />
 	<attribute name="Variable Names" value="" />
 	<component type="PhysicsWorld" id="1" />

+ 7 - 6
UISceneView2D/Resources/Components/UI.js

@@ -2,12 +2,13 @@
 
 var WIDTH = 512;
 var HEIGHT = 512;
-
+//UI component
 exports.component = function(self) {
-
+    //creates a new scene, but doesn't load it to the player
     var scene = Atomic.player.loadScene("Scenes/2DScene.scene");
-    var cameras = scene.getComponents("Camera", true);
-
+    //get camera from the scene
+    var camera = scene.getComponents("Camera", true)[0];
+    //create a new UIView
     var view = new Atomic.UIView();
 
     // Create a UIWindow
@@ -19,7 +20,7 @@ exports.component = function(self) {
 
     // The Scene View
     var sceneView = new Atomic.UISceneView();
-    sceneView.setView(scene, cameras[0]);
+    sceneView.setView(scene, camera);
     sceneView.autoUpdate = true;
     window.addChild(sceneView);
 
@@ -27,4 +28,4 @@ exports.component = function(self) {
     view.addChild(window);
     window.center();
 
-}
+}

+ 4 - 4
UISceneView2D/Resources/Scenes/2DScene.scene

@@ -5,10 +5,10 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="366" />
-	<attribute name="Next Replicated Component ID" value="1979" />
-	<attribute name="Next Local Node ID" value="16778510" />
-	<attribute name="Next Local Component ID" value="16777228" />
+	<attribute name="Next Replicated Node ID" value="367" />
+	<attribute name="Next Replicated Component ID" value="1980" />
+	<attribute name="Next Local Node ID" value="16778517" />
+	<attribute name="Next Local Component ID" value="16777234" />
 	<attribute name="Variables" />
 	<attribute name="Variable Names" value="" />
 	<component type="PhysicsWorld" id="1" />

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

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