0
votes

I was wondering if there was a way I could set the origin to the center of the screen.

for example I usually do this:

`origin = new vector2D(image.height / 2, image.width /2);

spritebatch.Draw(image, vector.zero,null, Color, 0, origin, none, 0); `

and now the origin of an image is on the middle. I want to be able to do a vector.zero and place the image on the middle of the screen with out doing what I usually do. Is that possible?

1

1 Answers

1
votes

That is not really how the coordinate system works, unless you are talking screen-space. In which case, the entire screen is mapped to [-1,-1](upper left) - [1,1](lower right). This is reather useless, so dont do that.

What you need to do is to make yourself a sprite-class, in which you perform the finding of origin of the sprite(texture) you are going to draw:

public class Sprite
{
    static Vector2 WorldOrigo = new Vector2(400, 240); //center of a 800x480 screen

    Texture2D Texture { get; set; }
    Vector2 Origin { get; set; }

    public Sprite(Texture2D texture)
    {
        Texture = texture;
        Origin = new Vector2(texture.Width / 2, texture.Height / 2);
    }

    public void Draw(Vector2 position, SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(Texture, WorldOrigo + position - Origin, Color.White);
    }
}

Note that this is just an example. You sprite would probably have code for animation and so on.