# My position is "changing" when handling animation

I'm trying to learn Monogames(Old XNA) and how to develop a 2d game.

I'm in the process of animating my sprites. It works but there are somethings that are weird to me.

For some reason when animating my sprites it "changes" the position when being animated WITHOUT changing the origin. Like so

When I have not changed my origin my character "shifts" his body upwards. Something he should not do.

Now if I change the origin to be the width and height of my frame this does not happend. Like so

Ass you can see the rectangle is still changing but my character does NOT shift in its position. I can't really understand why he shifts and DOES NOT shift.

The origin is at the top-left position of the rectangle.

Why does my character position shifts? I think it's something about offset with the different heights of the frames I am unsure. I don't understand how to work with offset.

EDIT.

//I have sheets with more animations (IDLE,WALK etc) This is how I get correct ones
List<CustomTexture2D.Frames> currentsheet = cts.frames.FindAll(x => x.filename.Contains(_currentstate.ToString()));
//Gets the information of the current frame (width, height, position on spritesheet)
var t = currentsheet.Where(x => x.filename.Contains(_currentframe.ToString())).FirstOrDefault();
//Without changing origin
_spriteBatch.Draw(cts.Texture, position, new Rectangle(new Point(t.frame.x, t.frame.y), new Point(t.frame.w, t.frame.h)), Color.White, rotate, new Vector2(0, 0), 1, SpriteEffects.None, 1);
//With changed origin
_spriteBatch.Draw(cts.Texture, position, new Rectangle(t.frame.x, t.frame.y, t.frame.w, t.frame.h), Color.White, rotate, new Vector2(t.frame.w, t.frame.h), 1, SpriteEffects.None, 1);

• Can you show us the code for each example? May 17 '19 at 11:42
• The code for drawing the sprite or how much of the code do you want? May 17 '19 at 11:44
• How much is required to reproduce the problem? That's usually a good metric to show enough for others to be able to offer good answers. May 17 '19 at 11:45
• @DMGregory added code. This is how I'm drawing the sprite. May 17 '19 at 12:00
• I don't have time to answer this now but I answered a very similar problem before. Basically, you need to set the origin point when you call the Draw method May 17 '19 at 22:43

If you look carefully at the first image the top left does not change position.

XNA does not know what is drawn in the sprite. So when you tell it to draw a sprite at (x,y) then it will draw that sprite at (x,y).

It's up to you to make sure the visuals actually match up. Either by making sure the character is always in the same spot relative to the top left, or by adding an offset to the (x,y) based on where the character is in the sprite.

• Yeah I know that top left does not change position. But how would I calculate the offset? English is not my main language so unsure what offset means. May 17 '19 at 12:41
• @tirri, for every sprite you will need to store that offset. Those would need to be determined manually. May 17 '19 at 13:04
• A common way to handle this offset that ratchet freak describes is to have the artist define a registration point for each frame, also called a "hotpoint" or "pivot", annotated in metadata for the animation, often made with a visual sprite editor tool. By subtracting the respective registration point when drawing each frame, you move them to a common coordinate space where the registration point is fixed at the origin, and the animation moves as needed around this controllable anchor. You can then add your desired sprite coordinates to place this anchored animation wherever you want on-screen. May 18 '19 at 8:20