Пример #1
0
 public void DrawSprite(Sprite sprite)
 {
     mySpriteBatch.Begin(SpriteSortMode.Deferred, blendState);
     int top = sprite.AnimationState * sprite.SquareSize; //top, left, bottom, and right of the source rectangle from the texture sheet.
     int left = sprite.AnimationFrame * sprite.SquareSize; //the rows are frames and columns are states.
     int bottom = top + sprite.SquareSize;
     int right = left + sprite.SquareSize;
     Vector2 superScreenCoordinates = new Vector2
         (
         //convert sprite.GameCoordinates to superScreenCoordinates using isometric transformation.  Or not.
             sprite.GameCoordinates.X,
             sprite.GameCoordinates.Y
         );
     Vector2 cameraCoordinates = new Vector2
         (//convert superscreen coordinates to camera coordinates (actual display coordinates) by substracting the Camera position.
         superScreenCoordinates.X - camera.CameraX,
         superScreenCoordinates.Y - camera.CameraY
         );
     //mySpriteBatch.Draw(sprite.TextureSheet, cameraCoordinates, new Rectangle(top, left, bottom, right), sprite.Color);
     mySpriteBatch.Draw(
         sprite.TextureSheet,
         cameraCoordinates,
         new Rectangle(top, left, bottom, right),
         sprite.Color,
         sprite.Rotation,
         new Vector2(sprite.SquareSize / 2, sprite.SquareSize / 2),
         1F,
         SpriteEffects.None,
         0F);
     mySpriteBatch.End();
 }
Пример #2
0
        public Sprite buildASprite(string texturePath)
        {
            string fullTexturePath = contentPath + texturePath;
            Texture2D texture;
            texture = Content.Load<Texture2D>(fullTexturePath);
            Sprite builtSprite = new Sprite(texture);
            spriteList.Add(builtSprite);

            //if (texturePath == "demo.png") //set SquareSize and CollisionBox on a per-sprite basis
            //{
            //    builtSprite.SquareSize = 45;
            //    int SquareSize = builtSprite.SquareSize;
            //    builtSprite.CollisionBox = new Rectangle(-SquareSize / 5, -SquareSize / 5, SquareSize / 5, SquareSize / 5);
            //}

            builtSprite.ImageName = texturePath;

            return spriteList[spriteList.Count - 1];
        }