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 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);
No comments:
Post a Comment