-
Notifications
You must be signed in to change notification settings - Fork 4
tutorial
#tween.core tutorial
-
clone the repo and place in an arcadia project
-
set up a basic scene with a sphere
- create a ns and def the sphere
(ns tutorial.core
(:require arcadia.core)
(:use [tween.core :as tween]))
(def sphere (object-named "Sphere"))(def jump (tween/position (Vector3. 0 3 0)))The resulting value is a tween.core.Tween instance, which stores the desired settings and can apply them to a game object.
Tweens are partially-associative, you can get specific keys (:duration :target :delay :+ :in :out :callback)
tutorial.core=> jump ;#<Tween tween.core.position_tween|1>
tutorial.core=> (:duration jump) ;1.0
tutorial.core=> (:target jump) ;(0.0, 3.0, 0.0)You can also assoc them, returning a new immutable proxy.
tutorial.core=> (def jump2 (assoc :duration jump 0.5)) ;#'tutorial.core/jump2
tutorial.core=> (= jump jump2) ;false- Use a Tween by invoking it on a GameObject
(jump sphere)If you apply it a second time, the Sphere won't move. Our tween is using a global target, but can be set to use relative values. We'll also adjust the duration from the default 1 second:
(def jump (tween/position (Vector3. 0 3 0) :+ 0.5))- Lets make a falling tween, and link the two
(def jump (tween/position (Vector3. 0 3 0) :+ 0.5 {:out :pow3}))
(def fall (tween/position (Vector3. 0 -3 0) :+ 0.5 {:in :pow3}))
(link! jump fall)Now when we invoke jump it results in a bounce:
(Note that we also added an option map with easing functions to mock gravity)
link! swaps an atom in the Tween that determines which functions are called after it has finished. We linked two Tweens, but any function can be used, as long as it takes 1 arg (the gameobject the tween was attached to)
(link! fall #(UnityEngine.Debug/Log (str "FELL:" %)))We could of linked fall back to jump to get a cycle, but lets use a anonymous fn to add a random delay in the loop
(link! fall #((assoc jump :delay (rand)) %))And just for fun:
(for [x (range 10)
z (range 10)
:let [go (create-primitive :sphere)
place (tween/position (Vector3. x 0.5 z) 0.1)]]
(do (link! place jump) (place go)))


