Exemplo n.º 1
0
    public static Scene MakeTestActionsScene()
    {
        TextureInfo Characters = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/PlanetCute/Objects.png", false), new Vector2i(7, 3));

        float world_scale = 0.036f;

        var sprite = new SpriteTile();

        sprite.TextureInfo = Characters;
        sprite.TileIndex1D = 2;
        sprite.Quad.S      = sprite.CalcSizeInPixels() * world_scale;
        sprite.CenterSprite();
        sprite.Color     = new Vector4(1.0f, 1.0f, 1.0f, 0.75f);
        sprite.BlendMode = BlendMode.Normal;

        var scene = new Scene()
        {
            Name = "Action tests"
        };

        scene.AddChild(sprite);

        var pos = new Vector2(0.0f, 0.0f);

        int writing_color_tag    = 333;
        int writing_position_tag = 65406;

        AddButton(scene, "MoveTo (0,0)", ref pos, () => { sprite.RunAction(new MoveTo(new Vector2(0.0f, 0.0f), 0.1f)); });
        AddButton(scene, "MoveBy (3,0)", ref pos, () => { sprite.RunAction(new MoveBy(new Vector2(3.0f, 0.0f), 0.1f)); });
        AddButton(scene, "ScaleBy (2,2)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(2.0f, 2.0f), 0.1f)); });
        AddButton(scene, "ScaleBy (0.5,0.5)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(0.5f, 0.5f), 0.1f)); });

        AddButton(scene, "TintTo White", ref pos, () =>
        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            sprite.RunAction(new TintTo(Math.SetAlpha(Colors.White, 0.75f), 2.0f)
            {
                Tag = writing_color_tag
            });
        }
                  );

        AddButton(scene, "TintTo Blue", ref pos, () =>
        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            sprite.RunAction(new TintTo(Math.SetAlpha(Colors.Blue, 0.75f), 2.0f)
            {
                Tag = writing_color_tag
            });
        }
                  );

        AddButton(scene, "Pingpong colors", ref pos, () =>

        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            var action12 = new TintTo(Colors.Green, 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var action13 = new TintTo(Colors.Magenta, 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var seq = new Sequence();
            seq.Add(action12);
            seq.Add(action13);
            var repeat0 = new RepeatForever()
            {
                InnerAction = seq, Tag = writing_color_tag
            };
            sprite.RunAction(repeat0);
        }
                  );

        AddButton(scene, "Pingpong position", ref pos, () =>

        {
            // prevent from running the same action twice
            // (we could also just hold an Action object somewhere and re-run, so that this check wouldn't be needed)
            if (sprite.GetActionByTag(writing_position_tag) != null)
            {
                sprite.StopActionByTag(writing_position_tag);
            }

            var action12 = new MoveTo(new Vector2(-5, 0), 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var action13 = new MoveTo(new Vector2(5, 0), 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var seq = new Sequence();
            seq.Add(action12);
            seq.Add(action13);
            var repeat0 = new RepeatForever()
            {
                InnerAction = seq, Tag = writing_position_tag
            };

            sprite.RunAction(repeat0);
        }
                  );

        AddButton(scene, "StopAllActions", ref pos, () => sprite.StopAllActions());

        scene.RegisterDisposeOnExit((System.IDisposable)Characters);

        return(scene);
    }