Friday, April 25, 2014

Sprite Animation in simple way

2014-04-25

Introduce  a new way to add sprite animations to XNA game class.
here are the code that need for it.

 public class Fire
    {
        Vector2 sposition;
        Rectangle spriteAnimateRect;
        Texture2D spriteCoin;

      
        int currentFrame = 0;
        int frameX = 0;
        int frameY = 0;
        float timer;
        int interval = 100;

        public Fire(ContentManager content,Vector2 position)
        {
            spriteCoin = content.Load<Texture2D>("fire_explosion");
            sposition = position;

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(spriteCoin, sposition,spriteAnimateRect, Color.White);
        }

        public void Update(GameTime gameTime)
        {
            spriteAnimateRect = new Rectangle(currentFrame + frameX, frameY, 120, 140);
            Animate(gameTime);
        }

        public void Animate(GameTime gameTime)
        {
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
            if (timer > interval)
            {

                timer = 0;
                currentFrame += 120;
              
                if (currentFrame >1725)
                {
                    currentFrame = 0;
                 
                }
             
            }
        }

Thursday, April 3, 2014

Attention Game 1

Attention Game 1

use NeuroSky mindwave device to control the "bird's velocity".

  • basic functionality are ok.
  • sounds has to be added.
  • attention level indicator has to be added.