Sfoglia il codice sorgente

Added new basic tween animation example

Björn Ritzl 5 anni fa
parent
commit
1de89efbe5

+ 20 - 2
examples/_main/loader.go

@@ -191,9 +191,9 @@ embedded_components {
   }
 }
 embedded_components {
-  id: "animation/tween"
+  id: "animation/basic_tween"
   type: "collectionproxy"
-  data: "collection: \"/examples/animation/tween/tween.collection\"\n"
+  data: "collection: \"/examples/animation/basic_tween/basic_tween.collection\"\n"
   "exclude: false\n"
   ""
   position {
@@ -658,3 +658,21 @@ embedded_components {
     w: 1.0
   }
 }
+embedded_components {
+  id: "animation/chained_tween"
+  type: "collectionproxy"
+  data: "collection: \"/examples/animation/chained_tween/chained_tween.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

@@ -103,7 +103,7 @@ function init(self)
 	self.index = {}
 	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn", "z_order" }
 	self.index["physics"] = { "dynamic", "kinematic", "raycast", "trigger" }
-	self.index["animation"] = { "spinner", "flipbook", "tween", "spine" }
+	self.index["animation"] = { "spinner", "flipbook", "chained_tween", "basic_tween", "spine" }
 	self.index["gui"] = { "button", "stencil", "load_texture", "pointer_over", "color"}
 	self.index["input"] = { "move", "text", "down duration", "mouse_and_touch" }
 	self.index["particles"] = { "particlefx", "modifiers" }

+ 1 - 1
examples/animation/tween/tween.collection → examples/animation/basic_tween/basic_tween.collection

@@ -4,7 +4,7 @@ embedded_instances {
   id: "bunny"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/animation/tween/bunny.script\"\n"
+  "  component: \"/examples/animation/basic_tween/bunny.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"

+ 7 - 0
examples/animation/basic_tween/basic_tween.md

@@ -0,0 +1,7 @@
+---
+title: Tween animation
+brief: This example shows how to tween animate the position of a game object.
+scripts: bunny.script
+---
+
+![tween](basic_tween.png)

+ 0 - 0
examples/animation/tween/tween.png → examples/animation/basic_tween/basic_tween.png


+ 18 - 0
examples/animation/basic_tween/bunny.script

@@ -0,0 +1,18 @@
+function init(self)
+    local to = vmath.vector3(400, 400, 0)
+    go.animate(".", "position", go.PLAYBACK_LOOP_PINGPONG, to, go.EASING_INOUTSINE, 2)
+end
+
+--[[
+1. In Lua, local variables must be declared prior to their use.
+   Since the functions `up_down()` and `left_right()` refer to 
+   each other we "forward declare" the names `up_down` and 
+   `left_right` before the function definitions.
+2. This function animates the game object position's y component,
+   then calls the function `left_right()` on completion.
+3. This function animates the game object position's x component,
+   then calls the function `up_down()` on completion.
+4. Start by calling the `up_down()` function.
+5. In parallell, tween the scale y component.
+6. And the sprite's tint x component (which is the red value).
+--]]

+ 0 - 0
examples/animation/tween/bunny.script → examples/animation/chained_tween/bunny.script


+ 57 - 0
examples/animation/chained_tween/chained_tween.collection

@@ -0,0 +1,57 @@
+name: "default"
+scale_along_z: 0
+embedded_instances {
+  id: "bunny"
+  data: "components {\n"
+  "  id: \"script\"\n"
+  "  component: \"/examples/animation/chained_tween/bunny.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: 60.0
+    y: 96.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
+  }
+}

+ 7 - 0
examples/animation/chained_tween/chained_tween.md

@@ -0,0 +1,7 @@
+---
+title: Tween animations chain
+brief: This example shows how to chain two tween animations of the position of a game object. In addition, the scale and tint is animated separately.
+scripts: bunny.script
+---
+
+![tween](chained_tween.png)

BIN
examples/animation/chained_tween/chained_tween.png


+ 0 - 7
examples/animation/tween/tween.md

@@ -1,7 +0,0 @@
----
-title: Tween animations
-brief: This example shows how to tween animate the position of a game object. Two such animations have been chained together. In addition, the scale and tint is animated separately.
-scripts: bunny.script
----
-
-![tween](tween.png)