When I start my application, the object spawns at the given position (given vector). But when I minimize the monogame window and reopen it, then the object is in the upper-left corner.
Why is this happening?
NOTE: this is my Draw
method:
public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
// Position is the object position
spriteBatch.Draw(textureImage, position, new Rectangle(
(currentFrame.X * frameSize.X),
(currentFrame.Y * frameSize.Y),
frameSize.X, frameSize.Y),
Color.White, 0, Vector2.Zero, 2, SpriteEffects.None, 0);
}
How the starting position is calculated:
// Vector2 position is the starting position for the object
public PlayerMovement(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffSet, Point currentFrame, Point startFrame, Point sheetSize, float speed, float speedMultiplier, float millisecondsPerFrame)
: base(textureImage, position, frameSize, collisionOffSet, currentFrame, startFrame, sheetSize, speed, speedMultiplier, millisecondsPerFrame)
{
children = new List<Sprite>();
}
I use Vector2 direction
to know which direction the sprite is facing:
public abstract Vector2 direction
{
get;
}
I use the get
in my PlayerMovement
class and return inputDirection * speed
(inputDirection
is a Vector2
)
Finally in my Update
method, I do position += direction
and I also check if the player isn't touching the borders of the screen(he can't move out the screen.).