cs 4730 ruminations on sprites in monogame martin kellogg, definitely not ph.d

20
CS 4730 Ruminations on Sprites in Monogame Martin Kellogg, definitely not Ph.D.

Upload: gwendoline-garrison

Post on 30-Dec-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

CS 4730

Ruminations on Sprites in MonogameMartin Kellogg, definitely not Ph.D.

CS 47302

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

CS 47303

What is a Sprite?• Any graphical content• Either 2D or 3D• We’ll restrict ourselves to

2D sprites

CS 47304

Coordinates• We care about three coordinate systems:

– Screen coordinates– World coordinates– Object coordinates

CS 47305

Screen and world coordinates

CS 47306

Object coordinates• Position of a pixel within an object

CS 47307

What about Monogame?• Implemented through the SpriteBatch class• Three important methods:

– Begin– Draw– End

CS 47308

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);

CS 47309

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)

CS 473010

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.

CS 473011

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.

CS 473012

Where to draw things?

• This means using vectors• They can describe positions (from the origin)

CS 473013

Transformations• A function T: →

• Examples include: – converting object to screen coordinates– translation– scale– rotation

2 2

CS 473014

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

CS 473015

Translation• Translation is just a fancy way of saying

movement• Equivalent to vector addition• Don’t need Matrix class

CS 473016

Scaling• Changing the size of objects• = • Tread carefully:

– Scaling is expensive– Scaling objects to make them larger can result in

“jaggies” - pixelated images

CS 473017

Rotation• Rotation around a fixed point• = • If you want to know why:

goto Thornton_B;

find(“APMA”);take(3080);

CS 473018

A final note about transforms• As a general rule, most transforms are NOT

commutative• Why?

CS 473019

An example

Rotate then Translate Translate then Rotate

CS 473020

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