150 likes | 231 Views
Basics of Graphics. Basics of Graphics. (4,0). (0,0). Pixels: “ dots ” that make up a picture Resolution: number of pixels in the whole picture (1024 x 768) Coordinates: pixel positions. (3,4). (0,3). Positioning. Remember that (0,0) is the upper left corner. Textels.
E N D
Basics of Graphics (4,0) (0,0) • Pixels: “dots” that make up a picture • Resolution: number of pixels in the whole picture (1024 x 768) • Coordinates: pixel positions (3,4) (0,3)
Positioning • Remember that (0,0) is the upper left corner
Textels • Coordinate value inside the texture (image) (0,0) (200,0) (0,0) (100,0)
Color Model • Primary colors: red, blue, green • Subtractive color model: Absence of all colors is white. (medium: ink, paint) • Additive color model: Adding all colors together creates white. (medium: light) • RGB color model: additive model of red, green, and blue light • Bit depth: number of distinct colors allowed • Humans can see 10 million colors, so 24-bit color is ideal.
Video Hardware • 2 parts: monitor & video card • Video card: memory cache for monitor • Pixels on monitor are points of light, so they fade away after a few milliseconds. • Monitor refreshes the scene continuously • Refresh rate: number of redraws per second (75-85 Hz)
Images • Transparency • Opaque • Transparent • Translucent
Images File Formats • Vector: describes image geometrically • Can be resized without degradation • Not supported • Raster: describes image by pixels • GIF: opaque or transparent, 8-bits of color, high compression • PNG: any transparency, up to 24 bit color, same compression as GIFs • JPEG: opaque, 24-bit only, better compression rate for photos • XNA Proprietary Format ????
XNA Basics • Program.cs – like Main, main entry point • Game1.cs – rename it! This is the main game driver • Content folder – for images and sounds • using statements – C# for “import” (copy XNA ones into new classes) • namespace – C# for “package” • colon is used for “extends”
Game Framework • Constructor • Initialize • Load/Unload Content • Update • Draw • Update/Draw usually based on time
New classes • Right-click on main folder, choose Add, then New Item • Choose class, and re-name the class before clicking “Add”
Content • Right-click on Content folder, choose New… Existing Item. Choose the kind of item you want and then browse for it. • Works for images and sounds • Stores as XNA Proprietary formats • Refer to content by their asset names (in the property window) • In LoadContent()… • Content.Load<Texture2D>(“imageName”); • Content.Load<SoundEffect>(“sound”);
SpriteBatch • Do the drawing in XNA • spriteBatch.Begin(); • spriteBatch.Draw… (many overloads) • spriteBatch.End();
GraphicsDeviceManager • Gives access to screen properties graphics.PreferredBackBufferWidth graphics.IsFullScreen = true;
Finally… • Don’t put too much in Game1. • Use your OO techniques! • Make a disco ball and a bouncing guy.