Rumina ons on Sprites in Monogame
Transcription
Rumina ons on Sprites in Monogame
Rumina'ons on Sprites in Monogame Mar'n Kellogg, definitely not Ph.D. CS 4730 Cunning Plan • Sprites are an abstrac7on of all graphical content • Three kinds of coordinates: world, screen, and object • We can manipulate sprites using linear algebra – Some examples include transla7on, scaling, and rota7on 2 CS 4730 What is a Sprite? • Any graphical content • Either 2D or 3D • We’ll restrict ourselves to 2D sprites 3 CS 4730 Coordinates • We care about three coordinate systems: – Screen coordinates – World coordinates – Object coordinates 4 CS 4730 Screen and world coordinates 5 CS 4730 Object coordinates • Posi7on of a pixel within an object 6 CS 4730 What about Monogame? • Implemented through the SpriteBatch class • Three important methods: – Begin – Draw – End 7 CS 4730 Back to front… • End() is easy – you call it when you’re finished drawing things! • Draw() is a touch more complex, but s7ll simple. Three arguments: – The image to draw – The posi7on at which to draw – A color to 7nt it (use Color.White most of the 7me) e.g. mySpriteBatch.Draw(background, Vector2.Zero, Color.White); 8 CS 4730 Back to front (con7nued) • 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 CS 4730 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 7mes his name was used as a 7tle by the German Hohenzollern dynasty. 10 CS 4730 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 CS 4730 Where to draw things? • This means using vectors • They can describe posi7ons (from the origin) 12 CS 4730 Transforma7ons 2 • A func7on T: → 2 • Examples include: – conver7ng object to screen coordinates – transla7on – scale – rota7on 13 CS 4730 The Matrix and Vector2 classes • This is how we can apply transforms in Monogame • Make a Vector2 for your posi7on • Apply matrix opera7ons to the Vector2 14 CS 4730 Transla7on • Transla7on is just a fancy way of saying movement • Equivalent to vector addi7on • Don’t need Matrix class 15 CS 4730 Scaling • Changing the size of objects • [█■𝑠↓𝑥 0 0 𝑠↓𝑦 ][█■𝑥𝑦 ] = [█■𝑠↓𝑥 𝑥𝑠↓𝑦 𝑦 ] • Tread carefully: – Scaling is expensive – Scaling objects to make them larger can result in “jaggies” -‐ pixelated images 16 CS 4730 Rota7on • Rota7on around a fixed point • [█■cos(𝜃) sin(𝜃) −sin(𝜃) cos(𝜃) ][█■𝑥𝑦 ] = [█■𝑥′𝑦′ ] • If you want to know why: goto Thornton_B; find(“APMA”); take(3080); 17 CS 4730 A final note about transforms • As a general rule, most transforms are NOT commuta7ve • Why? 18 CS 4730 An example Rotate then Translate Translate then Rotate 19 CS 4730 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 mul7ple choice ques7ons and an op7onal 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: hkp://bit.ly/MAnk4i 20 CS 4730