Beispiel #1
0
        public override bool draw(int x, int y)
        {
            if (_imageAtlas == null)
            {
                throw new FormatException("Unable to draw sprite " + _name);
            }

            _frameTracker += _imageAtlas.FrameRate;

            if (_frameTracker >= 60)
            {
                _frameTracker = 0;
                frameX++;
                _framesPassed++;

                if (frameX >= _imageAtlas.tileXCount)
                {
                    frameX = 0;
                    frameY++;

                    if (frameY >= _imageAtlas.tileYCount)
                    {
                        frameY = 0;
                    }
                }
            }
            _size       = _imageAtlas.getTile(frameX, frameY);
            _position.X = x; _position.Y = y;
            //CGraphics.spriteBatch.Draw(_imageAtlas.sourceImage, _position, _size, Color.White);

            if (!(_flipV || _flipH))
            {
                CGraphics.spriteBatch.Draw(CTextures.rawTextures[CTextures.textures[_atlasName].source], _position, _size, Color.White);
            }
            else if (_flipV)
            {
                CGraphics.spriteBatch.Draw(CTextures.rawTextures[CTextures.textures[_atlasName].source], _position, _size, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.FlipVertically, 0);
            }
            else if (_flipH)
            {
                CGraphics.spriteBatch.Draw(CTextures.rawTextures[CTextures.textures[_atlasName].source], _position, _size, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.FlipHorizontally, 0);
            }
            base.draw(x, y);
            if (_framesPassed == _totalFrames - 1)
            {
                _framesPassed = 0;
                frameX        = 0; frameY = 0;
                return(true); //this is used to determine if the animation ended
            }
            return(false);
        }
Beispiel #2
0
        private void _animate()
        {
            int lastFrameTime = CMasterControl.gameTime.ElapsedGameTime.Milliseconds;

            _timeForCurrentFrame += lastFrameTime;
            double endFrameTime = _frameRateLookup[_imageAtlas.FrameRate] - lastFrameTime / 2.0;

            int relativeFrameCount = _timeForCurrentFrame / lastFrameTime;
            int maxFrameCount      = (int)(_frameRateLookup[_imageAtlas.FrameRate] / (double)lastFrameTime);

            _framesPassed++;

            _size = _imageAtlas.getTile(frameX, frameY);
        }