Exemplo n.º 1
0
        /// <summary>
        /// Adds an animation to the CellAnimation Manager using a different Texture Key and Texture2D
        /// </summary>
        /// <param name="animationKey">Key for Animation Namr</param>
        /// <param name="textureName">Texture2D Name from Pipeline tool</param>
        /// <param name="celCount">Number of Cells in Animation. CelCount has Number of Rows and Number of Columns</param>
        /// <param name="framesPerSecond">Frame Rate to play back animation in frames per secong</param>
        /// <param name="texture">Texture 2D to load</param>

        public void AddAnimation(string animationKey, string textureName,
                                 Texture2D texture, CelCount celCount, int framesPerSecond)
        {
            if (texture == null)
            {
                this.Game.Content.Load <Texture2D>(textureName);
            }
            if (!textures.ContainsKey(textureName))
            {
                textures.Add(textureName, texture);
            }

            int celWidth  = (int)(textures[textureName].Width / celCount.NumberOfColumns);
            int celHeight = (int)(textures[textureName].Height / celCount.NumberOfRows);

            int numberOfCels = celCount.NumberOfColumns * celCount.NumberOfRows;

            //we create a cel range by passing in start location of 1,1
            //and end with number of column and rows
            //2,1  =   1,1,2,1  ;    4,2  =  1,1,4,2

            AddAnimation(animationKey, textureName,
                         new CelRange(1, 1, celCount.NumberOfColumns, celCount.NumberOfRows),
                         celWidth, celHeight, numberOfCels,
                         framesPerSecond);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds an animation to the CellAnimation Manager
        /// </summary>
        /// <param name="animationKey">Key for Animation Namr</param>
        /// <param name="textureName">Texture2D Name from Pipeline tool</param>
        /// <param name="celCount">Number of Cells in Animation. CelCount has Number of Rows and Number of Columns</param>
        /// <param name="framesPerSecond">Frame Rate to play back animation in frames per second</param>
        public void AddAnimation(string animationKey, string textureName,
                                 CelCount celCount, int framesPerSecond)
        {
            //Make sure texture is unique
            if (!textures.ContainsKey(textureName))
            {
                //Add texture to Dictionary using Texture Name
                textures.Add(textureName, this.Game.Content.Load <Texture2D>(textureName));
            }

            int celWidth  = (int)(textures[textureName].Width / celCount.NumberOfColumns); //find cell width by diving Texture Width by number Columns
            int celHeight = (int)(textures[textureName].Height / celCount.NumberOfRows);   // find cell height by diving Texture Width by number of Rows

            int numberOfCels = celCount.NumberOfColumns * celCount.NumberOfRows;

            //we create a cel range by passing in start location of 1,1
            //and end with number of column and rows
            //2,1  =   1,1,2,1  ;    4,2  =  1,1,4,2

            AddAnimation(animationKey, textureName,
                         new CelRange(1, 1, celCount.NumberOfColumns, celCount.NumberOfRows),
                         celWidth, celHeight, numberOfCels,
                         framesPerSecond);
        }