Example #1
0
        /// <summary>
        ///     Crear un nuevo Sprite animado
        /// </summary>
        /// <param name="texturePath">path de la textura animada</param>
        /// <param name="frameSize">tamaño de un tile de la animacion</param>
        /// <param name="totalFrames">cantidad de frames que tiene la animacion</param>
        /// <param name="frameRate">velocidad en cuadros por segundo</param>
        public TgcAnimatedSprite(string texturePath, Size frameSize, int totalFrames, float frameRate)
        {
            enabled          = true;
            currentFrame     = 0;
            this.frameSize   = frameSize;
            this.totalFrames = totalFrames;
            currentTime      = 0;
            playing          = true;

            //Crear textura
            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, texturePath);

            //Sprite
            Sprite         = new TgcSprite();
            Sprite.Texture = texture;

            //Calcular valores de frames de la textura
            textureWidth    = texture.Width;
            textureHeight   = texture.Height;
            framesPerColumn = (int)textureWidth / frameSize.Width;
            framesPerRow    = (int)textureHeight / frameSize.Height;
            var realTotalFrames = framesPerRow * framesPerColumn;

            if (realTotalFrames > totalFrames)
            {
                throw new Exception(
                          "Error en AnimatedSprite. No coinciden la cantidad de frames y el tamaño de la textura: " +
                          totalFrames);
            }

            setFrameRate(frameRate);
        }
Example #2
0
 /// <summary>
 ///     Renderizar Sprite
 /// </summary>
 /// <param name="sprite">Sprite a dibujar</param>
 public void drawSprite(TgcSprite sprite)
 {
     dxSprite.Transform = sprite.TransformationMatrix;
     dxSprite.Draw(sprite.Texture.D3dTexture, sprite.SrcRect, Vector3.Empty, Vector3.Empty, sprite.Color);
 }