Jump to content
  • Advertisement
Sign in to follow this  
raidzero

C# Xna Make an object follow player

This topic is 2539 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

I currently have a static sprite that I can move using the keyboard.
I want to bind another sprite to. So far the code I have for it is:
testObjectSprite.Draw(spriteBatch, new Vector2(mainSprite.Position.X - 8, mainSprite.Position.Y - 20));

I tried placing that code within this one:
if (ms.LeftButton == ButtonState.Pressed)
{

}

And the program crashes, when I click the left mouse button..

Also, how could I get my testObjectSprite to rotate between two angles?
I researched and look at some other codes where they find the origin, point where it rotates, but I get lost when it actual calculate how it rotates.

Share this post


Link to post
Share on other sites
Advertisement
Hi. Have you run your program in debug mode ? It should tell you the problem, usually in the form of an exception. What is that exception saying ? Also, you should post more code. We cannot tell you anything relevant from the amount of code you provided.

Share this post


Link to post
Share on other sites

I currently have a static sprite that I can move using the keyboard.
I want to bind another sprite to. So far the code I have for it is:
testObjectSprite.Draw(spriteBatch, new Vector2(mainSprite.Position.X - 8, mainSprite.Position.Y - 20));

I tried placing that code within this one:
if (ms.LeftButton == ButtonState.Pressed)
{

}

And the program crashes, when I click the left mouse button..

Also, how could I get my testObjectSprite to rotate between two angles?
I researched and look at some other codes where they find the origin, point where it rotates, but I get lost when it actual calculate how it rotates.



Arth is right.

But one thing appears to me:

where do you place this code?

if (ms.LeftButton == ButtonState.Pressed)
{

}



You have to put this code in your update method. Supposing this is what you did, you even say that you have inserted the draw() method inside the if statement. This means you have the draw method in the update(): this is not good as in the update you just have to do updates, not drawnings.

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!