Browse Source

Create scene from main.js, add some instructions, hoist some resource management out of spawn loop

Josh Engebretson 10 years ago
parent
commit
7719878c38

+ 0 - 1
Butterflies/Resources/Components/Butterfly.js

@@ -6,7 +6,6 @@ var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
 exports.component = function(self) {
 
     var node = self.node;
-    node.scale2D = [2, 2];
     self.speed = 1 + 2 * Math.random();
     self.rotationSpeed = 10;
     self.direction = Math.random() * Math.PI * 2;

+ 6 - 4
Butterflies/Resources/Components/Spawner.js

@@ -1,9 +1,11 @@
 'atomic component';
 
+var viewport = Atomic.renderer.getViewport(0);
+var animationSet = Atomic.cache.getResource("AnimationSet2D", "Sprites/butterfly.scml");
+var particleEffect = Atomic.cache.getResource("ParticleEffect2D", "Particles/particle.pex");
+
 exports.component = function(self) {
 
-    var viewport = Atomic.renderer.getViewport(0);
-    var animationSet = Atomic.cache.getResource("AnimationSet2D", "Sprites/butterfly.scml");
 
     self.update = function(timeStep) {
 
@@ -30,10 +32,10 @@ exports.component = function(self) {
             var pos = viewport.screenToWorldPoint(mpos[0], mpos[1], 0);
             emitter.position2D = pos;
             var pex = emitter.createComponent("ParticleEmitter2D");
-            pex.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/particle.pex");
+            pex.effect = particleEffect;
 
         }
 
     }
 
-}
+}

+ 0 - 5
Butterflies/Resources/Scenes.asset

@@ -1,5 +0,0 @@
-{
-	"version": 1,
-	"guid": "2ba799b159e9302bcd82f1bfa61d1085",
-	"FolderImporter": {}
-}

+ 0 - 48
Butterflies/Resources/Scenes/Scene.scene

@@ -1,48 +0,0 @@
-<?xml version="1.0"?>
-<scene id="1">
-	<attribute name="Name" value="" />
-	<attribute name="Time Scale" value="1" />
-	<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="369" />
-	<attribute name="Next Replicated Component ID" value="1985" />
-	<attribute name="Next Local Node ID" value="16778496" />
-	<attribute name="Next Local Component ID" value="16777216" />
-	<attribute name="Variables" />
-	<attribute name="Variable Names" value="" />
-	<component type="Octree" id="2" />
-	<component type="DebugRenderer" id="3" />
-	<component type="Renderer2D" id="1976" />
-	<component type="JSComponent" id="1981">
-		<attribute name="ComponentFile" value="JSComponentFile;Components/Spawner.js" />
-	</component>
-	<node id="361">
-		<attribute name="Is Enabled" value="true" />
-		<attribute name="Name" value="Camera" />
-		<attribute name="Position" value="0 0 -5" />
-		<attribute name="Rotation" value="1 0 0 0" />
-		<attribute name="Scale" value="1 1 1" />
-		<attribute name="Variables" />
-		<component type="Camera" id="1973">
-			<attribute name="Near Clip" value="0" />
-			<attribute name="Orthographic" value="true" />
-			<attribute name="Orthographic Size" value="8" />
-		</component>
-	</node>
-	<node id="368">
-		<attribute name="Is Enabled" value="true" />
-		<attribute name="Name" value="Node" />
-		<attribute name="Position" value="0 0 0" />
-		<attribute name="Rotation" value="1 0 0 0" />
-		<attribute name="Scale" value="1 1 1" />
-		<attribute name="Variables" />
-		<component type="ParticleEmitter2D" id="1984">
-			<attribute name="Layer" value="1" />
-			<attribute name="Order in Layer" value="1" />
-			<attribute name="Particle Effect" value="ParticleEffect2D;Particles/particle.pex" />
-			<attribute name="Sprite " value="Sprite2D;Particles/texture.png" />
-			<attribute name="Blend Mode" value="addalpha" />
-		</component>
-	</node>
-</scene>

+ 0 - 5
Butterflies/Resources/Scenes/Scene.scene.asset

@@ -1,5 +0,0 @@
-{
-	"version": 1,
-	"guid": "f2b371bcae7cd3102046cd26214fab71",
-	"SceneImporter": {}
-}

+ 55 - 1
Butterflies/Resources/Scripts/main.js

@@ -1,3 +1,57 @@
 // This script is the main entry point of the game
 
-Atomic.player.loadScene("Scenes/Scene.scene");
+// create a scene
+var scene = new Atomic.Scene();
+
+// create an octree component
+scene.createComponent("Octree");
+
+// create out camera
+var cameraNode = scene.createChild("Camera");
+var camera = cameraNode.createComponent("Camera");
+
+// setup as 2D
+camera.setOrthographic(true);
+camera.setOrthoSize(Atomic.graphics.height * Atomic.PIXEL_SIZE / 2);
+
+// create a viewport
+var viewport = new Atomic.Viewport(scene, camera);
+Atomic.renderer.setViewport(0, viewport);
+
+// create our spawner component
+scene.createJSComponent("Components/Spawner.js");
+
+createInstructions();
+
+function createInstructions() {
+
+    var view = 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();
+
+    // specify the layout region
+    layout.rect = view.rect;
+
+    view.addChild(layout);
+
+    // we're laying out on the X axis so "position" controls top and bottom alignment
+    layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_RIGHT_BOTTOM;
+    // while "distribution" handles the Y axis
+    layout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM;
+    
+    var fd = new Atomic.UIFontDescription();
+    fd.id = "Vera";
+    fd.size = 18;
+    
+    var scoreText = new Atomic.UIEditField();
+    scoreText.fontDescription = fd;
+    scoreText.readOnly = true;
+    scoreText.multiline = true;
+    scoreText.adaptToContentSize = true;
+    scoreText.text = "Atomic Butterflies\nLeft Mouse - Spawn Butterflies\nRight Click - Spawn Particles";
+    layout.addChild(scoreText);
+
+
+}