Exemplo n.º 1
0
        private void OnCameraShake(params object[] args)
        {
            float str = args.Length > 0 ? (float)args[0] : 10.0f;
            float dur = args.Length > 1 ? (float)args[1] : 1.0f;

            // Get a random number [-1..1]
            float randX = ((float)FP.Rand(200) - 100.0f) / 100.0f;
            float randY = ((float)FP.Rand(200) - 100.0f) / 100.0f;

            // Scale it by the strength
            offsetX = str * (randX);
            offsetY = str * (randY);

            if (prevShaker != null)
            {
                prevShaker.Cancel();
            }

            var shaker = new MultiVarTween(OnShakeDone, Tween.ONESHOT);

            Parent.AddTween(shaker);
            shaker.Tween(this, new { offsetX = 0.0f, offsetY = 0.0f }, dur, Ease.ElasticOut);
            shaker.Start();

            prevShaker = shaker;
        }
Exemplo n.º 2
0
        public void MoveToNextPos()
        {
            nextNode = FP.Next(nextNode, positionNodes, true);

            //set the animation
            if (nextNode.X - this.X > 0)
            {
                spritemap.FlippedX = true;
            }
            else if (nextNode.X - this.X < 0)
            {
                spritemap.FlippedX = false;
            }

            if (!isAttacking)
            {
                if (nextNode.X - this.X == 0)
                {
                    spritemap.Play("Idle");
                }
                else
                {
                    spritemap.Play("Move");
                }
            }

            var twoon = new MultiVarTween(MoveToNextPos, ONESHOT);

            twoon.Tween(this, new { X = nextNode.X, Y = nextNode.Y }, 5.0f);
            AddTween(twoon, true);
        }
Exemplo n.º 3
0
        public void MoveToNextPos()
        {
            currentPosition = FP.Next(currentPosition, positionNodes, true);
            var twoon = new MultiVarTween(MoveToNextPos, ONESHOT);

            twoon.Tween(this, new { X = currentPosition.X, Y = currentPosition.Y }, 5.0f);
            AddTween(twoon, true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tweens numeric public properties of an Object.
        /// Shorthand for creating a MultiVarTween tween, starting it and adding it to a Tweener.
        /// </summary>
        /// <param name="target">The object containing the properties to tween.</param>
        /// <param name="values">An object containing key/value pairs of properties and target values.</param>
        /// <param name="duration">Duration of the tween.</param>
        /// <param name="options">An object containing key/value pairs of the following optional parameters:
        ///                             type        Tween type.
        ///                             complete    Optional completion callback function.
        ///                             ease        Optional easer function.
        ///                             tweener     The Tweener to add this Tween to.
        ///                             delay       A length of time to wait before starting this tween.
        /// </param>
        /// <example>FP.Tween(object, new { x = 500, y = 350 }, 2.0f, new { ease = easeFunction, complete = onComplete } );</example>
        /// <returns>The added MultiVarTween object.</returns>
        public static MultiVarTween Tween(object target, object values, float duration, object options = null)
        {
            uint type = Punk.Tween.ONESHOT;

            Tween.OnComplete complete = null;
            Tween.Easer      ease     = null;
            Tweener          tweener  = FP.Tweener;
            float            delay    = 0;

            if (target is Tweener)
            {
                tweener = target as Tweener;
            }

            if (options != null)
            {
                if (options is Tween.OnComplete)
                {
                    complete = options as Tween.OnComplete;
                }
                if (options.HasOwnProperty("type"))
                {
                    type = options.GetProp <uint>("type");
                }
                if (options.HasOwnProperty("complete"))
                {
                    complete = options.GetProp <Tween.OnComplete>("complete");
                }
                if (options.HasOwnProperty("ease"))
                {
                    ease = options.GetProp <Tween.Easer>("ease");
                }
                if (options.HasOwnProperty("tweener"))
                {
                    tweener = options.GetProp <Tweener>("tweener");
                }
                if (options.HasOwnProperty("delay"))
                {
                    delay = options.GetProp <float>("delay");
                }
            }

            var tween = new MultiVarTween(complete, type);

            tween.Tween(target, values, duration, ease, delay);
            tweener.AddTween(tween);
            return(tween);
        }