Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

C# IF Statement - XNA

Hi Guys,

I created an IF Statement for my XNA game which allows you to move the position of the characters:

if (activeCharacter.DestY > activeCharacter.OriginY - 48)           // Do I change all of 'activeCharacter' to classroom
        {
         //STOP           
            activeCharacter.DestY = activeCharacter.DestY - 1;}
         //ANIMATION

        else if (activeCharacter.DestX <  680)
        {
            activeCharacter.DestX = activeCharacter.DestX + 1;}

        else
            if (activeCharacter.DestY < 566)

        { activeCharacter.DestY = activeCharacter.DestY + 1; }

        Console.WriteLine(activeCharacter.DestY);

The last part of the code stops the 'active character' from moving to it's last postion as the game updates and goes back to the top of the code.

In my console it shows that the first if causes the last else if to minus 1 and then add one:

Console: 1,2,1,2,1,2,1,2

It was recommended to me that I may need to recode the whole if statement but I am not too sure how I am suppose to do this.

Can someone please tell me stop this from happening?

Thanks!