If statement causing xna sprites to draw frame by frame

Posted by user1489599 on Game Development See other posts from Game Development or by user1489599
Published on 2012-12-07T14:07:34Z Indexed on 2012/12/07 17:39 UTC
Read the original article Hit count: 268

Filed under:
|
|
|

I’m a bit new to XNA but I wanted to write a simple program that would fire a cannon ball from a cannon at a 45 degree angle. It works fine outside of my keyboard i/o if statement, but when I encapsulate the code around an if statement checking to see if the user hits the space bar, the sprite will draw one frame at a time every time the space bar is hit.

This is the code in question

if (currentKeyboardState.IsKeyUp(Keys.Space) && previousKeyboardState.IsKeyDown(Keys.Space) && !skullBall.Alive)
        {
            //works outside the keyboard input if statement   //{
            skullBall.Position = cannon.Position;
            skullBall.DeltaY = -(float)(Math.Sin(MathHelper.ToRadians(45)) * 50/*39.7577*/ * time + 0.5 * (gravity * (time * time)));
            skullBall.DeltaX = (float)(Math.Cos(MathHelper.ToRadians(45)) * 50/*39.7577*/ * time);
            skullBall.Alive = true;           //}
        }

The skull ball represents the cannon ball and the cannon is just the starting point. DeltaX and DeltaY are the values I’m using to update the cannon balls position per update. I know it's dumb to have the cannon ball start at the cannons position every time the update is called but it’s not really noticeable right now.

I was wondering if after examining my code, if anyone noticed any errors that would cause the sprite to display frame by frame instead of drawing it as a full animation of the cannon ball leaving the cannon and moving from there.

© Game Development or respective owner

Related posts about XNA

Related posts about sprites