Example #1
0
        private Roga2dBaseInterval buildWalkInterval()
        {
            List<Roga2dAnimationKeyFrame> keyFrames = new List<Roga2dAnimationKeyFrame>();
            int[] frames = new int[4]{1, 0, 1, 2};
            for (int i = 0; i < 4; i++) {
                Roga2dAnimationKeyFrame keyFrame = new Roga2dAnimationKeyFrame();
                keyFrame.Rect = new Rect(96 + frames[i] * 32, 0, 32, 32);
                keyFrame.Id = this.TextureID;
                keyFrame.Duration = Roga2dUtils.TimeToFrame(0.2f);
                keyFrame.Type = Roga2dAnimationKeyFrameType.Image;
                keyFrame.PixelCenter = new Vector2(0, 0);
                keyFrame.PixelSize = new Vector2(32, 32);
                keyFrames.Add(keyFrame);
            }

            return new Roga2dLoop(new Roga2dSourceInterval(this.Sprite, keyFrames, null, null), 0);
        }
    public static void TestUpdate()
    {
        Roga2dRenderObject renderObject = new Roga2dRenderObject(null, new Vector2(32, 48), new Vector2(1, 1), new Rect(10, 10, 32, 48));
        Roga2dSprite sprite = new Roga2dSprite(renderObject);

        List<Roga2dAnimationKeyFrame> keyFrames = new List<Roga2dAnimationKeyFrame>();

        Roga2dAnimationKeyFrame keyFrame = new Roga2dAnimationKeyFrame();
        keyFrame.FrameNo = 0;
        keyFrame.Rect = new Rect(10, 10, 32, 48);
        keyFrame.Id = "test";
        keyFrame.Duration = 3;
        keyFrame.Type = Roga2dAnimationKeyFrameType.Image;
        keyFrame.PixelCenter = new Vector2(1, 1);
        keyFrames.Add(keyFrame);

        keyFrame = new Roga2dAnimationKeyFrame();
        keyFrame.FrameNo = 3;
        keyFrame.Rect = new Rect(20, 10, 22, 48);
        keyFrame.Id = "test2";
        keyFrame.Duration = 2;
        keyFrame.Type = Roga2dAnimationKeyFrameType.Image;
        keyFrame.PixelCenter = new Vector2(2, 2);
        keyFrames.Add(keyFrame);

        keyFrame = new Roga2dAnimationKeyFrame();
        keyFrame.FrameNo = 5;
        keyFrame.Rect = new Rect(20, 10, 22, 48);
        keyFrame.Id = "test3";
        keyFrame.Duration = 1;
        keyFrame.Type = Roga2dAnimationKeyFrameType.Image;
        keyFrame.PixelCenter = new Vector2(3, 3);
        keyFrames.Add(keyFrame);

        keyFrame = new Roga2dAnimationKeyFrame();
        keyFrame.FrameNo = 6;
        keyFrame.Rect = new Rect(20, 10, 22, 48);
        keyFrame.Id = "test4";
        keyFrame.Duration = 2;
        keyFrame.Type = Roga2dAnimationKeyFrameType.Image;
        keyFrame.PixelCenter = new Vector2(4, 4);
        keyFrames.Add(keyFrame);

        Roga2dSourceInterval interval = new Roga2dSourceInterval(sprite, keyFrames, null, null);

        interval.Start();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(10, 10, 32, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(1, 1));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(10, 10, 32, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(1, 1));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(10, 10, 32, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(1, 1));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(10, 10, 32, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(1, 1));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(20, 10, 22, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(2, 2));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(20, 10, 22, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(2, 2));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(20, 10, 22, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(3, 3));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(20, 10, 22, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(4, 4));
        Tester.Ok(!interval.IsDone());

        interval.Update();
        Tester.Match(sprite.RenderObject.SrcRect, new Rect(20, 10, 22, 48));
        Tester.Match(sprite.RenderObject.PixelCenter, new Vector2(4, 4));
        Tester.Ok(interval.IsDone());
        interval.Update();

        sprite.Destroy();
    }
    private void EmitAnimation(Roga2dAnimationKeyFrame keyFrame)
    {
        this.sprite.UpdatePriority();
        // Emit the new animation (emitted animation won't be controled by this instance anymore)
        Roga2dAnimation animation = Roga2dUtils.LoadAnimation(keyFrame.Id, false, this.sprite.Alpha, this.sprite.Priority, this.settings, this.options);

        // Apply emit velocity
        if (keyFrame.MaxEmitSpeed > 0) {
            float speed = keyFrame.MinEmitSpeed + (keyFrame.MaxEmitSpeed - keyFrame.MinEmitSpeed) * Random.value;
            float angle = keyFrame.MinEmitAngle + (keyFrame.MaxEmitAngle - keyFrame.MinEmitAngle) * Random.value;
            float rad = (angle / 180) * Mathf.PI;
            animation.Node.Velocity = Roga2dUtils.pixelToLocal(new Vector2(speed * Mathf.Cos(rad), speed * Mathf.Sin(rad)));
        }

        if (this.settings.Player == null) {
            Debug.LogError("No AnimationPlayer is defined in root");
        }

        this.settings.Player.Play(this.settings.Root, this.sprite.Transform, animation, null);
    }