Browse Source

UIExample

Josh Engebretson 11 years ago
parent
commit
4a43a9f3a6

+ 16 - 0
UIExample/Resources/Components/Star.js

@@ -0,0 +1,16 @@
+var game = Atomic.game;
+var node = self.node;
+
+function start() {
+
+    var sprite2D = node.createComponent("StaticSprite2D");
+    sprite2D.sprite = game.getSprite2D("Sprites/star.png");
+    sprite2D.blendMode = Atomic.BLEND_ALPHA;
+
+}
+
+function update(timeStep) {
+
+    node.roll(timeStep * 100);
+    
+}

+ 85 - 0
UIExample/Resources/Components/UI.js

@@ -0,0 +1,85 @@
+
+var game = Atomic.game;
+var ui = game.ui;
+var root = ui.getRoot();
+
+var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
+root.defaultStyle = uiStyle;
+
+var window = new Atomic.Window();
+root.addChild(window);
+
+window.setMinSize(384, 192);
+
+window.setAlignment(Atomic.HA_CENTER, Atomic.VA_CENTER);
+
+window.setLayout(Atomic.LM_VERTICAL, 6, [6, 6, 6, 6]);
+window.setName("Window");
+
+var titleBar = new Atomic.UIElement();
+titleBar.setMinSize(0, 24);
+titleBar.setVerticalAlignment(Atomic.VA_TOP);
+titleBar.setLayoutMode(Atomic.LM_HORIZONTAL);
+
+// Create the Window title Text
+var windowTitle = new Atomic.Text();
+windowTitle.setName("WindowTitle");
+windowTitle.setText("Star Maker!");
+titleBar.addChild(windowTitle);
+
+window.addChild(titleBar);
+
+var button = new Atomic.Button();
+button.setName ("Star Button");
+button.setMinHeight(24);
+
+var buttonText = new Atomic.Text();
+
+buttonText.text = "Add Star";
+var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
+
+buttonText.setFont(font, 12);
+buttonText.color = [0, 1, 0, 1];
+
+buttonText.horizontalAlignment = Atomic.HA_CENTER;
+buttonText.verticalAlignment = Atomic.VA_CENTER;
+button.addChild(buttonText);
+
+window.addChild(button);
+
+window.movable = true;
+window.resizeable = true;
+
+window.setStyleAuto();
+titleBar.setStyleAuto();
+windowTitle.setStyleAuto();
+button.setStyleAuto();
+
+self.onMouseClick = function(element) {
+
+    var width = game.graphics.width * Atomic.PIXEL_SIZE * 0.5;
+    var height = game.graphics.height * Atomic.PIXEL_SIZE * 0.5;
+    
+    var x = -width/2 + width * Math.random();
+    var y = -height/2 + height * Math.random();
+
+   if (element.name == "Star Button") {
+        var starNode = game.scene.createChild("Star");
+        starNode.createJSComponent("Star");
+        starNode.position2D = [x, y];
+   }
+    
+}
+
+function start() {
+
+    self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
+
+}
+
+function update(timeStep) {
+
+    
+    
+}
+

+ 22 - 0
UIExample/Resources/Scripts/main.js

@@ -0,0 +1,22 @@
+// This script is the main entry point of the game
+
+var game = Atomic.game;
+
+// called at the start of play
+function Start() {
+
+    var game = Atomic.game;
+
+    // create a 2D scene
+    game.createScene2D();
+    
+    var uiNode = game.scene.createChild("UI");
+    uiNode.createJSComponent("UI");
+
+}
+
+// called per frame
+function Update(timeStep) {
+
+
+}

BIN
UIExample/Resources/Sprites/star.png


+ 0 - 0
UIExample/UIExample.atomic