Sign in to follow this  

C# Xna Make an object follow player

This topic is 2322 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:
[code]testObjectSprite.Draw(spriteBatch, new Vector2(mainSprite.Position.X - 8, mainSprite.Position.Y - 20));[/code]

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

}[/code]
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
[quote name='Key' timestamp='1312519877' post='4844866']
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:
[code]testObjectSprite.Draw(spriteBatch, new Vector2(mainSprite.Position.X - 8, mainSprite.Position.Y - 20));[/code]

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

}[/code]
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.
[/quote]


Arth is right.

But one thing appears to me:

where do you place this code?
[code]
if (ms.LeftButton == ButtonState.Pressed)
{

}
[/code]


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

This topic is 2322 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this