コード例 #1
0
        /// <summary>
        /// Creates and returns a Rectangle for the exact position of a player sprite on the spritesheet.
        /// </summary>
        /// <param name="sprite"></param>
        /// <returns></returns>
        private static Rectangle getPlayerTextureRect(PLAYER_SPRITES sprite)
        {
            int rectX = -1;
            int rectY = -1;

            //x
            switch (sprite)
            {
                case PLAYER_SPRITES.M_DOWN_1:
                case PLAYER_SPRITES.M_LEFT_1:
                case PLAYER_SPRITES.M_RIGHT_1:
                case PLAYER_SPRITES.M_UP_1:
                    rectX = 0;
                    break;
                case PLAYER_SPRITES.M_DOWN_2:
                case PLAYER_SPRITES.M_LEFT_2:
                case PLAYER_SPRITES.M_RIGHT_2:
                case PLAYER_SPRITES.M_UP_2:
                    rectX = 1;
                    break;
                case PLAYER_SPRITES.M_DOWN_3:
                case PLAYER_SPRITES.M_LEFT_3:
                case PLAYER_SPRITES.M_RIGHT_3:
                case PLAYER_SPRITES.M_UP_3:
                    rectX = 2;
                    break;
                case PLAYER_SPRITES.F_DOWN_1:
                case PLAYER_SPRITES.F_LEFT_1:
                case PLAYER_SPRITES.F_RIGHT_1:
                case PLAYER_SPRITES.F_UP_1:
                    rectX = 3;
                    break;
                case PLAYER_SPRITES.F_DOWN_2:
                case PLAYER_SPRITES.F_LEFT_2:
                case PLAYER_SPRITES.F_RIGHT_2:
                case PLAYER_SPRITES.F_UP_2:
                    rectX = 4;
                    break;
                case PLAYER_SPRITES.F_DOWN_3:
                case PLAYER_SPRITES.F_LEFT_3:
                case PLAYER_SPRITES.F_RIGHT_3:
                case PLAYER_SPRITES.F_UP_3:
                    rectX = 5;
                    break;
            }

            //y
            switch (sprite)
            {
                case PLAYER_SPRITES.M_DOWN_1:
                case PLAYER_SPRITES.M_DOWN_2:
                case PLAYER_SPRITES.M_DOWN_3:
                case PLAYER_SPRITES.F_DOWN_1:
                case PLAYER_SPRITES.F_DOWN_2:
                case PLAYER_SPRITES.F_DOWN_3:
                    rectY = 0;
                    break;
                case PLAYER_SPRITES.M_LEFT_1:
                case PLAYER_SPRITES.M_LEFT_2:
                case PLAYER_SPRITES.M_LEFT_3:
                case PLAYER_SPRITES.F_LEFT_1:
                case PLAYER_SPRITES.F_LEFT_2:
                case PLAYER_SPRITES.F_LEFT_3:
                    rectY = 1;
                    break;
                case PLAYER_SPRITES.M_RIGHT_1:
                case PLAYER_SPRITES.M_RIGHT_2:
                case PLAYER_SPRITES.M_RIGHT_3:
                case PLAYER_SPRITES.F_RIGHT_1:
                case PLAYER_SPRITES.F_RIGHT_2:
                case PLAYER_SPRITES.F_RIGHT_3:
                    rectY = 2;
                    break;
                case PLAYER_SPRITES.M_UP_1:
                case PLAYER_SPRITES.M_UP_2:
                case PLAYER_SPRITES.M_UP_3:
                case PLAYER_SPRITES.F_UP_1:
                case PLAYER_SPRITES.F_UP_2:
                case PLAYER_SPRITES.F_UP_3:
                    rectY = 3;
                    break;
            }

            //Incase I missed assigning the sprite a location above
            if (rectX == -1 || rectY == -1)
                throw new Exception("Sprite location has not been specified!");

            return new Rectangle(rectX * SpriteWidth, rectY * SpriteHeight, SpriteWidth, SpriteHeight);
        }
コード例 #2
0
 /// <summary>
 /// Gets a Rectangle used to specify the exact location of a given player sprite on the spritesheet.
 /// </summary>
 /// <param name="sprite">Name of the sprite to get rectangle of</param>
 /// <returns>Returns an empty Rectangle if sprite name not found</returns>
 public static Rectangle getPlayerSpriteRect(PLAYER_SPRITES sprite)
 {
     if (PlayerSprites.ContainsKey(sprite))
         return PlayerSprites[sprite];
     return new Rectangle();
 }