Jump to content
  • Advertisement
Sign in to follow this  
Robo-Link

[.net] Help animating

This topic is 4078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey guys, can you help me out? i am having trouble animating my guy in my game for some reason. here is the code i am using to animate him. note: right now i am only trying to work on his moving left, so just look at those parts. anyway, right now when i hit left he goes to left animation 1, but i want him to cycle through 2 and 3 and he doesn't. he goes through 2 and 3 after i stop pressing left. edit: the game is in C# .net and using some direct x9 managed for sound.
public void drawPlayer(Graphics g, worldMap wm, sound s1)
        {
            if (this.state == STATE_STAND)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraStand, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }

                else
                {
                    g.DrawImage(sakariStand, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_LEFT1 && anidone)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraLeft1, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                    this.state = STATE_LEFT2;
                    this.anidone = false;
                }

                else
                {
                    g.DrawImage(sakariLeft1, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_RIGHT1)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraRight1, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }

                else
                {
                    g.DrawImage(sakariRight1, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_LEFT2 && anidone)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraLeft2, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                    this.state = STATE_LEFT3;
                    this.anidone = false;
                }

                else
                {
                    g.DrawImage(sakariLeft2, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_RIGHT2)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraRight2, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }

                else
                {
                    g.DrawImage(sakariRight2, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_LEFT3 && anidone)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraLeft3, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                    this.state = STATE_LEFT1;
                    this.anidone = false;
                }

                else
                {
                    g.DrawImage(sakariLeft3, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            if (this.state == STATE_RIGHT3)
            {
                if (this.playerVar == 0)
                {
                    g.DrawImage(soraRight3, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }

                else
                {
                    g.DrawImage(sakariRight3, new Rectangle(this.getX() - wm.getX(), this.getY() - wm.getY(), size, size));
                }
            }

            this.anidone = true;
        }

Share this post


Link to post
Share on other sites
Advertisement
Here's a tutorial that covers animation (and some other stuff like collision detection). It also contains a video that explains the concepts.

Try to focus on understanding the basic principles of animation and how the code in that tutorial is structured.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!