Explorar el Código

Added z-order sprites example.

Mikael Säker hace 7 años
padre
commit
fed4df388b

BIN
assets/images/rainbow.png


+ 3 - 0
assets/sprites.atlas

@@ -37,6 +37,9 @@ images {
 images {
   image: "/assets/images/smoke.png"
 }
+images {
+  image: "/assets/images/rainbow.png"
+}
 animations {
   id: "bee"
   images {

+ 18 - 0
examples/_main/loader.go

@@ -460,3 +460,21 @@ embedded_components {
     w: 1.0
   }
 }
+embedded_components {
+  id: "basics/z_order"
+  type: "collectionproxy"
+  data: "collection: \"/examples/basics/z_order/z_order.collection\"\n"
+  "exclude: false\n"
+  ""
+  position {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+}

+ 1 - 1
examples/_main/menu.gui_script

@@ -100,7 +100,7 @@ end
 
 function init(self)
 	self.index = { "basics", "physics", "animation", "gui", "input", "particles", "sound", "render", "camera", "debug" }
-	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn" }
+	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn", "z_order" }
 	self.index["physics"] = { "dynamic", "kinematic", "trigger" }
 	self.index["animation"] = { "spinner", "flipbook", "tween", "spine" }
 	self.index["gui"] = { "button", "stencil", "load_texture", "pointer_over"}

+ 97 - 0
examples/basics/z_order/z_order.collection

@@ -0,0 +1,97 @@
+name: "default"
+scale_along_z: 0
+embedded_instances {
+  id: "gameobject"
+  data: "components {\n"
+  "  id: \"script\"\n"
+  "  component: \"/examples/basics/z_order/z_order.script\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  "embedded_components {\n"
+  "  id: \"sprite\"\n"
+  "  type: \"sprite\"\n"
+  "  data: \"tile_set: \\\"/assets/sprites.atlas\\\"\\n"
+  "default_animation: \\\"bunny2_ready\\\"\\n"
+  "material: \\\"/builtins/materials/sprite.material\\\"\\n"
+  "blend_mode: BLEND_MODE_ALPHA\\n"
+  "\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  ""
+  position {
+    x: 120.0
+    y: 100.0
+    z: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale3 {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+  }
+}
+embedded_instances {
+  id: "background"
+  data: "embedded_components {\n"
+  "  id: \"sprite\"\n"
+  "  type: \"sprite\"\n"
+  "  data: \"tile_set: \\\"/assets/sprites.atlas\\\"\\n"
+  "default_animation: \\\"rainbow\\\"\\n"
+  "material: \\\"/builtins/materials/sprite.material\\\"\\n"
+  "blend_mode: BLEND_MODE_ALPHA\\n"
+  "\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  ""
+  position {
+    x: 360.0
+    y: 180.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale3 {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+  }
+}

+ 10 - 0
examples/basics/z_order/z_order.md

@@ -0,0 +1,10 @@
+---
+title: Z-order
+brief: This example shows how to put one sprite in front of another
+scripts: z_order.script
+---
+
+![z order](z_order.png)
+
+There is one game object containing the background sprite. It is set at Z position 0.
+The bunny is another game object containing a sprite. The bunny game object is at Z position 1.

BIN
examples/basics/z_order/z_order.png


+ 8 - 0
examples/basics/z_order/z_order.script

@@ -0,0 +1,8 @@
+function init(self)
+	go.animate(".", "position.x", go.PLAYBACK_LOOP_PINGPONG, 600, go.EASING_INOUTSINE, 3) -- <1>
+end
+
+--[[
+1. Animate the game object's ("." is shorthand for the current game object) x position between
+   start position and 600.
+--]]