Ejemplo n.º 1
0
        /// <summary>
        /// Returns a sprite containing the given text, with substitutions
        /// for special character sequences.
        /// </summary>
        private CompositeSprite CreateTextSprite(string text)
        {
            CompositeSprite sprite = new CompositeSprite();

            float x = 0f;

            string[] parts = text.Split('_');
            foreach (string part in parts)
            {
                Sprite partSprite;
                switch (part)
                {
                case "A": partSprite = _buttonA; break;

                case "B": partSprite = _buttonB; break;

                default: partSprite = new TextSprite(_font, part); break;
                }
                partSprite.Position = new Vector2(x, 0f);

                x += partSprite.Size.X;
                sprite.Add(partSprite);
            }

            return(sprite);
        }
Ejemplo n.º 2
0
        private Sprite CreateCompositeSprite(XElement spriteElem)
        {
            CompositeSprite composite = new CompositeSprite();

            foreach (XElement childSpriteElem in spriteElem.Elements())
            {
                composite.Add(CreateSprite(childSpriteElem));
            }
            return(composite);
        }
Ejemplo n.º 3
0
 public SpriteMover(CompositeSprite compositeSprite)
 {
     if (compositeSprite.transform.position != compositeSprite.BoundingSprite.bounds.center)
     {
         throw new ArgumentException($"{nameof(compositeSprite)} " +
                                     $"must be positioned in the center of {nameof(compositeSprite.BoundingSprite)}");
     }
     _spriteRenderer = compositeSprite.BoundingSprite;
     _spriteParent   = compositeSprite.gameObject;
 }
Ejemplo n.º 4
0
            /// <summary>
            /// Creates a new text menu entry.
            /// </summary>
            /// <param name="label">The unhighlighted label to show.</param>
            /// <param name="text">The text to show.</param>
            public TextMenuEntry(TextSprite label, TextSprite text) : base(null)
            {
                LabelSprite = label;
                TextSprite  = text;

                CompositeSprite composite = new CompositeSprite(LabelSprite, TextSprite);

                LabelSprite.Position = Vector2.Zero;
                TextSprite.Position  = new Vector2(LabelSprite.Size.X + LabelSprite.Font.MeasureString(" ").X, 0);
                Sprite = composite;
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Shows this guide with the given text.
        /// </summary>
        /// <param name="text">The text to display.</param>
        public void Show(string text)
        {
            CompositeSprite textSprite = _bubble.GetSprite <CompositeSprite>("Text");

            textSprite.Clear();
            textSprite.Add(CreateTextSprite(text));

            _bubble.GetSprite("Money").Color = Color.TransparentWhite;

            _bubbleAnimation = _bubble.GetAnimation("Show");
            _bubbleAnimation.Start();
        }
Ejemplo n.º 6
0
        protected override void LoadContent()
        {
            //// other stuffs
            lastState              = Keyboard.GetState();
            currentState           = DevStates.AnimatedSpriteTesting;
            lastMovingSpriteUpdate = TimeSpan.Zero;
            _spriteBatch           = new SpriteBatch(GraphicsDevice);

            fontManager = new FontManager(GraphicsDevice);
            font        = fontManager.GetFont("Content\\PlayfairDisplayRegular-ywLOY.ttf", 32);
            font2       = fontManager.GetFont("Content\\PlayfairDisplayRegular-ywLOY.ttf", 16);



            //// create and configure our sprite manager
            manager = new TextureManager(GraphicsDevice);
            manager.AutoTextureAtlasBalancingIntervalMilliseconds = 5000;

            //// register all of the textures we'll be using
            var animationSize  = new Point(400, 450);
            var hullSize       = new Point(288, 192);
            var hullSizeVector = new Vector2(hullSize.X, hullSize.Y);
            var tireSize       = new Point(45, 45);
            var tireSizeVector = new Vector2(tireSize.X, tireSize.Y);
            var textures       = new List <(string, Point?, string?)>()
            {
                ("TextureAtlasTesting\\11-6.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\beautiful-sunset-33.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\chloe4.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\gorgeous-f2-goldendoodle-puppies-5a7de534c591b.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\OIP.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\R3d398e62bb9b79f54b5c49b4e5f32925.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\Rdb919eda1b98929d3a17685a6d3d7ef8.jpg", ChooseRandomSize(), null),
                ("TextureAtlasTesting\\Refd96265ac3da1f5b5dc5277f1082d15.jpg", ChooseRandomSize(), null),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_1.jpg", animationSize, "woman1"),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_2.jpg", animationSize, "woman2"),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_3.jpg", animationSize, "woman3"),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_4.jpg", animationSize, "woman4"),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_5.jpg", animationSize, "woman5"),
                ("AnimationTesting\\woman-silhouette-walk-cycle-vector_6.jpg", animationSize, "woman6"),
                ("SpriteTesting\\spr_sportscar_0.png", hullSize, "static_car"),
                ("CompositeSpriteTesting\\spr_sportscar_0_hull.png", hullSize, "car_hull"),
                ("CompositeSpriteTesting\\spr_sportscar_0_tire.png", tireSize, "car_tire"),
                ("CompositeSpriteTesting\\spr_sportscar_0_tire_2.png", tireSize, "car_tire2"),
                ("CompositeSpriteTesting\\spr_sportscar_0_tire_3.png", tireSize, "car_tire3"),
                ("CompositeSpriteTesting\\spr_sportscar_0_tire_4.png", tireSize, "car_tire4")
            };
            var texturesLoadInfos = new List <TextureLoadInfo>();

            for (var i = 0; i < textures.Count; i++)
            {
                texturesLoadInfos.Add(new TextureLoadInfo(textures[i].Item3 ?? $"image{i}", $"Content\\{textures[i].Item1}", textures[i].Item2));
            }
            manager.LoadTextures(texturesLoadInfos);

            //// create sprites

            // Simple Sprites
            sprite1 = new Sprites.SimpleSprite(manager, "static_car1", "static_car", hullSizeVector);
            sprite2 = new Sprites.SimpleSprite(manager, "static_car2", "static_car", hullSizeVector);

            // Composite Sprites
            var tire1Location = new Vector2(43, 92);
            var tire2Location = new Vector2(213, 92);

            compositeSprite1 = new CompositeSprite(
                manager,
                "car_1",
                hullSizeVector,
                new Sprites.SimpleSprite(manager, "hull", "car_hull", hullSizeVector),
                new SimpleSprite(manager, "tire1", "car_tire", tire1Location, tireSizeVector),
                new SimpleSprite(manager, "tire2", "car_tire", tire2Location, tireSizeVector)
                );
            compositeSprite2 = new CompositeSprite(
                manager,
                "car_2",
                hullSizeVector,
                new Sprites.SimpleSprite(manager, "hull", "car_hull", hullSizeVector),
                new Sprites.Sprite(manager, "tire1", "car_tire", tire1Location, tireSizeVector),
                new Sprites.Sprite(manager, "tire2", "car_tire", tire2Location, tireSizeVector)
                );

            // Composite AnimatedSprites
            var tire_animation = new Animation(
                "tire",
                true,
                new Frame[]
            {
                new Frame("t1", "car_tire", 100),
                new Frame("t1", "car_tire2", 100),
                new Frame("t1", "car_tire3", 100),
                new Frame("t1", "car_tire4", 100)
            }
                );

            compositeAnimatedSprite1 = new CompositeSprite(
                manager,
                "a_car_1",
                hullSizeVector,
                new Sprites.SimpleSprite(manager, "hull", "car_hull", hullSizeVector),
                new AnimatedSprite(
                    manager,
                    "tire1",
                    tire1Location,
                    tireSizeVector,
                    animations: new Animation(tire_animation)
                    ),
                new AnimatedSprite(
                    manager,
                    "tire2",
                    tire2Location,
                    tireSizeVector,
                    animations: new Animation(tire_animation)
                    )
                );
            compositeAnimatedSprite2 = new CompositeSprite(
                manager,
                "a_car_2",
                hullSizeVector,
                new Sprites.SimpleSprite(manager, "hull", "car_hull", hullSizeVector),
                new AnimatedSprite(
                    manager,
                    "tire1",
                    tire1Location,
                    tireSizeVector,
                    animations: new Animation(tire_animation)
                    ),
                new AnimatedSprite(
                    manager,
                    "tire2",
                    tire2Location,
                    tireSizeVector,
                    animations: new Animation(tire_animation)
                    )
                );

            // Animated Sprites
            var frameTime = 75;

            animatedSprite1 = new AnimatedSprite(
                manager,
                "walking_women",
                Vector2.Zero,
                new Vector2(animationSize.X, animationSize.Y),
                animations: new Animation(
                    "walking",
                    true,
                    new Frame[]
            {
                new Frame("f1", "woman1", frameTime),
                new Frame("f2", "woman2", frameTime),
                new Frame("f3", "woman3", frameTime),
                new Frame("f4", "woman4", frameTime),
                new Frame("f5", "woman5", frameTime),
                new Frame("f6", "woman6", frameTime)
            }
                    )
                );
            animatedSprite2 = new AnimatedSprite(
                manager,
                "walking_women2",
                Vector2.Zero,
                new Vector2(animationSize.X, animationSize.Y),
                animations: new Animation(
                    "walking",
                    true,
                    new Frame[]
            {
                new Frame("f1", "woman1", frameTime),
                new Frame("f2", "woman2", frameTime),
                new Frame("f3", "woman3", frameTime),
                new Frame("f4", "woman4", frameTime),
                new Frame("f5", "woman5", frameTime),
                new Frame("f6", "woman6", frameTime)
            }
                    )
                );

            ChangeState(currentState, DevStates.SimpleSpriteTesting);
        }