210 likes | 364 Views
Ruminations on Sprites in Monogame. Martin Kellogg, definitely not Ph.D. Cunning Plan. Sprites are an abstraction of all graphical content Three kinds of coordinates: world, screen, and object We can manipulate sprites using linear algebra
E N D
Ruminations on Sprites in Monogame Martin Kellogg, definitely not Ph.D.
Cunning Plan • Sprites are an abstraction of all graphical content • Three kinds of coordinates: world, screen, and object • We can manipulate sprites using linear algebra • Some examples include translation, scaling, and rotation 2
What is a Sprite? • Any graphical content • Either 2D or 3D • We’ll restrict ourselves to 2Dsprites 3
Coordinates • We care about three coordinate systems: • Screen coordinates • World coordinates • Object coordinates 4
Object coordinates • Position of a pixel within an object 6
What about Monogame? • Implemented through the SpriteBatch class • Three important methods: • Begin • Draw • End 7
Back to front… • End() is easy – you call it when you’re finished drawing things! • Draw() is a touch more complex, but still simple. Three arguments: • The image to draw • The position at which to draw • A color to tint it (use Color.White most of the time) e.g. mySpriteBatch.Draw(background, Vector2.Zero, Color.White); 8
Back to front (continued) • The Begin() method is the most complex • You can pass it a variety of parameters that control how everything is drawn • Or you can just pass it nothing (easiest and therefore most recommended choice) 9
Trivia (Classics)! • This Roman general and statesman held the consulship for 59 BCE with Marcus Bibulus. Having completed the consulship, he held proconsular command in Gaul for nearly ten years before famously returning over the Rubicon river in January, 49. In later times his name was used as a title by the German Hohenzollern dynasty. 10
And another (Games)… • Published in Japan in 2002 under the name Fuuin no tsurugi, this role-playing game follows a young noble of the Lycian League as he struggles to defend his homeland from the invasion of the neighboring kingdom of Bern. This noble, Roy, later went on to appear in an installment of a famous series of fighters directed by Masahiro Sakurai. 11
Where to draw things? • This means using vectors • They can describe positions(from the origin) 12
Transformations 2 2 • A function T: → • Examples include: • converting object to screen coordinates • translation • scale • rotation 13
The Matrix and Vector2 classes • This is how we can apply transforms in Monogame • Make a Vector2 for your position • Apply matrix operations to the Vector2 14
Translation • Translation is just a fancy way of saying movement • Equivalent to vector addition • Don’t need Matrix class 15
Scaling • Changing the size of objects • = • Tread carefully: • Scaling is expensive • Scaling objects to make them larger can result in “jaggies” - pixelated images 16
Rotation • Rotation around a fixed point • = • If you want to know why: gotoThornton_B; find(“APMA”); take(3080); 17
A final note about transforms • As a general rule, most transforms are NOT commutative • Why? 18
An example Rotate then TranslateTranslate then Rotate 19
Wrap up • Your Physical prototypes are DUE in lab FRIDAY • Thanks for listening! • I’d really appreciate feedback on the lecture, so I set up this form. If y’all have a moment (it’s only two multiple choice questions and an optional free response) I’d appreciate it if you’d fill it out and let me know how I did! • Another way to get to the form: http://bit.ly/MAnk4i 20