Example #1
0
        //Creates a LayeredSprite. LayeredSprites are sprites composed of multiple sprites.
        //  For example, a base body sprite combined with an armor sprite and a weapon sprite.
        //  The names given are to identify the different layers if you want to modify them later (for example, replace the character's weapon).
        //  Note that this asks for SPRITES, not IMAGES. As such, each layer can also have multiple images (see CreateMultiSprite).
        //  Each sprite has to be created in advance before creating the LayeredSprite to contain them.
        public static LayeredSprite CreateLayeredSprite(Sprite[] sprites, string[] names = null, int x = 0, int y = 0)
        {
            LayeredSprite lspr = new LayeredSprite();

            for (int i = 0; i < sprites.Length; i++)
            {
                if (names == null)
                {
                    lspr.AddLayer(sprites[i].name, sprites[i]);
                }
                else lspr.AddLayer(names[i], sprites[i]);
            }
            lspr.SetPosition(x, y);
            gObjects.Add(lspr);

            return lspr;
        }
Example #2
0
File: Game1.cs Project: VDZx/VBXSE
        public void StartGame()
        {
            //-----------------Creating a normal sprite----------------
            //Create the background
            Sprite backgroundSprite = SpriteEngine.CreateSprite("background");
            backgroundSprite.depth = 800;

            //---------------Creating a sprite with position--------------
            //Create a building at (200, 200)
            Sprite buildingSprite = SpriteEngine.CreateSprite("building", 200, 50, 1f);
            buildingSprite.depth = -(50 + buildingSprite.GetImage().Height); //Set its depth equal to the negative value of the Y of the bottom of the sprite.
            //(Note that the engine supports transparency, mspaint just doesn't.)

            //---------------Creating a multi-layer sprite---------------
            //Create layers to build the player with
            Sprite heads = new Sprite(
                new Texture2D[] { SpriteEngine.textures["head1"], SpriteEngine.textures["head2"], SpriteEngine.textures["head3"] },
                new string[] { "head1", "head2", "head3" });
            Sprite bodies = new Sprite(
                new Texture2D[] { SpriteEngine.textures["body1"], SpriteEngine.textures["body2"], SpriteEngine.textures["body3"] },
                new string[] { "body1", "body2", "body3" });
            Sprite legs = new Sprite(
                 new Texture2D[] { SpriteEngine.textures["legs1"], SpriteEngine.textures["legs2"], SpriteEngine.textures["legs3"] },
                 new string[] { "legs1", "legs2", "legs3" });
            //Create the player at (500, 650)
            player = SpriteEngine.CreateLayeredSprite(new Sprite[] { heads, bodies, legs }, new string[] { "head", "body", "legs" }, 500, 650);

            //--------------Creating an animated sprite---------------
            //Create an animated sign at (700, 400)
            Sprite sign = SpriteEngine.CreateMultiSprite(new string[] { "Anim1", "Anim2", "Anim3" }, 700, 300, 1f);
            sign.depth = -(300 + sign.GetImage().Height); //Set depth
            Animation anim = new Animation("text", "Anim1", 3, 100);
            sign.AddAnimation(anim.name, anim);
            sign.ChangeAnimation("text");

            //-------------Creating a GText-------
            instructionText = SpriteEngine.CreateGText("Arrows to move around, Q to change head, W to change body, E to change legs, Enter to fake loading screen.", 300, 250);
            instructionText.depth = -250; //It will be behind the building

            //-----------Setting a load screen----
            //Note: Loading support is very basic and it kinda sucks. Build your own for fancy loading.
            Sprite loadSprite = new Sprite(SpriteEngine.textures["loading"], Vector2.Zero);
            SpriteEngine.loadingGObjects.Add(loadSprite);
        }