Browse Source

Updating Particles2D

Josh Engebretson 10 years ago
parent
commit
3827cd05ef

+ 1 - 0
Particles2D/.gitignore

@@ -0,0 +1 @@
+Cache/*

+ 5 - 0
Particles2D/Resources.asset

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

+ 5 - 0
Particles2D/Resources/Components.asset

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

+ 13 - 15
Particles2D/Resources/Components/ParticleSystem.js

@@ -1,23 +1,21 @@
-var game = Atomic.game;
-var node = self.node;
+'atomic component';
 
-var emitter;
+exports.component = function(self) {
 
-self.setEffect = function(name) {
+    var node = self.node;
 
-    emitter.effect = game.cache.getResource("ParticleEffect2D", "Particles/" + name + ".pex");
+    var emitter = node.getComponent("ParticleEmitter2D");
 
-}
+    self.subscribeToEvent("PlayHearts", function() {
+        emitter.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/love.pex");
+    });
 
-function start() {
-
-	emitter = node.createComponent("ParticleEmitter2D");
-	
-	self.setEffect("love");
-	
-}
-
-function update(timeStep) {	
+    self.subscribeToEvent("PlaySpark", function() {
+        emitter.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/explode.pex");
+    });
 
+    self.subscribeToEvent("PlaySnow", function() {
+        emitter.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/snow.pex");
+    });
 
 }

+ 7 - 0
Particles2D/Resources/Components/ParticleSystem.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "ae5835133de7349b7d52c47374863b73",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 26 - 50
Particles2D/Resources/Components/UI.js

@@ -1,67 +1,43 @@
-// Atomic Component
+'atomic component';
 
-var game = Atomic.game;
-var node = self.node;
+var fd = new Atomic.UIFontDescription();
+fd.id = "Vera";
+fd.size = 22;
 
-var ui = game.ui;
-var root = ui.getRoot();
+function createButton(self, text, event, layout) {
 
-var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
+    var button = new Atomic.UIButton();
+    button.text = text;
+    button.fontDescription = fd;
 
-var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
-root.defaultStyle = uiStyle;
+    button.gravity = Atomic.UI_GRAVITY_RIGHT;
 
-var container = new Atomic.UIElement();
-container.horizontalAlignment = Atomic.HA_RIGHT;
-container.verticalAlignment = Atomic.VA_CENTER;
-container.layoutMode = Atomic.LM_VERTICAL;
+    button.onClick = function() {
 
-root.addChild(container);
+        self.sendEvent(event);
 
-var buttons = {};
+    }
 
-function addButton(name, text, callback) {
+    layout.addChild(button);
 
-    var button = new Atomic.Button();
-    
-    button.setName(name);
-    button.setMinWidth(120);
-    button.setMinHeight(24);
-
-    var buttonText = new Atomic.Text();
-    buttonText.text = text;
-    buttonText.setFont(font, 12);
-    buttonText.color = [0, 1, 0, 1];
-
-    buttonText.horizontalAlignment = Atomic.HA_CENTER;
-    buttonText.verticalAlignment = Atomic.VA_CENTER;
-    button.addChild(buttonText); 
-    container.addChild(button);
-    button.setStyleAuto();   
-    
-    buttons[name] = callback;       
-   
 }
 
-addButton("Explosion", "Explosion", function() { ParticleSystem.setEffect("explode"); }); 
-addButton("Hearts", "Hearts", function() { ParticleSystem.setEffect("love"); }); 
-addButton("Snow", "Snow", function() { ParticleSystem.setEffect("snow"); }); 
+exports.component = function(self) {
+  
+    // root view
+    self.uiView = new Atomic.UIView();
 
-function start() {
+    var layout = new Atomic.UILayout();
+    layout.rect = self.uiView.rect;
 
-}
+    layout.axis = Atomic.UI_AXIS_Y;
 
-self.onMouseClick = function(element) {
+    layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_GRAVITY;
 
-    var name = element.name;
-    
-    buttons[name]();
-    
-}
+    self.uiView.addChild(layout);
 
+    createButton(self, "Play Hearts", "PlayHearts", layout);
+    createButton(self, "Play Snow", "PlaySnow", layout);
+    createButton(self, "Play Spark", "PlaySpark", layout);
 
-function update(timeStep) {
-
-    self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
-
-}
+}

+ 7 - 0
Particles2D/Resources/Components/UI.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "aa4e37b6fb17154a3501228d9d8f8d6c",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 5 - 0
Particles2D/Resources/Particles.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "0561f6130e79f8093e082b19b6a7d792",
+	"FolderImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/explode.pex.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "f0fdf0b95b1f0ca182e1cdd282f95dcb",
+	"PEXImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/heart.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "50e0167935661ea5f630658b945346f8",
+	"TextureImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/love.pex.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "a5d8be7322ac27adb8edb7b40b4beb1f",
+	"PEXImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/snow.pex.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "fbab50b2cbd5561ea943492f9a3117ab",
+	"PEXImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/snow.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "e45e50d456279a7522e4f069ee7258ca",
+	"TextureImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Particles/spark.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "2ff7952f76c63c63b719225323271695",
+	"TextureImporter": {}
+}

+ 5 - 0
Particles2D/Resources/Scenes.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "089297b41ff61a90d2915bc0e0988fbb",
+	"FolderImporter": {}
+}

+ 63 - 0
Particles2D/Resources/Scenes/Scene.scene

@@ -0,0 +1,63 @@
+<?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="365" />
+	<attribute name="Next Replicated Component ID" value="1980" />
+	<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="PhysicsWorld" id="1" />
+	<component type="Octree" id="2" />
+	<component type="DebugRenderer" id="3" />
+	<component type="Renderer2D" id="1976" />
+	<node id="2">
+		<attribute name="Is Enabled" value="true" />
+		<attribute name="Name" value="Zone" />
+		<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="Zone" id="4">
+			<attribute name="Bounding Box Min" value="-10000 -10000 -10000" />
+			<attribute name="Bounding Box Max" value="10000 10000 10000" />
+			<attribute name="Ambient Color" value="0.4 0.4 0.4 1" />
+		</component>
+	</node>
+	<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="5" />
+		</component>
+		<component type="JSComponent" id="1977">
+			<attribute name="ComponentFile" value="JSComponentFile;Components/UI.js" />
+		</component>
+	</node>
+	<node id="363">
+		<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="1975">
+			<attribute name="Particle Effect" value="ParticleEffect2D;Particles/love.pex" />
+			<attribute name="Sprite " value="Sprite2D;Particles/heart.png" />
+			<attribute name="Blend Mode" value="addalpha" />
+		</component>
+		<component type="JSComponent" id="1978">
+			<attribute name="ComponentFile" value="JSComponentFile;Components/ParticleSystem.js" />
+		</component>
+	</node>
+</scene>

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

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

+ 5 - 0
Particles2D/Resources/Scripts.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "4af760b01575e555e556511fc74d776d",
+	"FolderImporter": {}
+}

+ 4 - 21
Particles2D/Resources/Scripts/main.js

@@ -1,28 +1,11 @@
-
 // This script is the main entry point of the game
-require("AtomicGame");
-
-Atomic.game.init(start, update);
-
-
-// called at the start of play
-function start() {
-
-	var game = Atomic.game;
 
-	// create a 2D scene
-	game.createScene2D();
+var scene = Atomic.player.loadScene("Scenes/Scene.scene");
 
-    var ui = game.scene.createChild("UI");
-    ui.createJSComponent("UI");
-    
-    var node = game.scene.createChild("ParticleSystem");
-    ParticleSystem = node.createJSComponent("ParticleSystem");
-
-}
-
-// called per frame
+// called per frame, optional
 function update(timeStep) {
 
 
 }
+
+exports.update = update;

+ 7 - 0
Particles2D/Resources/Scripts/main.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "4c919989edb8ac1a240f704e10c739d2",
+	"JavascriptImporter": {
+		"IsComponentFile": false
+	}
+}