CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
Advertisements

Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Creating Games For Windows, Xbox 360, and Windows Phone 7 Ryan Plemons
Iframes & Images Using HTML.
Dan Waters, Academic Relations Manager, Microsoft.
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
Chapter 17 Creating Images for the Web. Chapter Lessons Learn about Web features Optimize images for Web use Create a button for a Web page Create slices.
XP Tutorial 4 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Personalizing Your Windows Environment Tutorial 4.
Chapter 4 Adding Images. Inserting and Aligning Images Using CSS When you choose graphics to add to a web page, it’s important to use graphic files in.
File Formats By Jack Turner. Raster (Bitmap) Raster or bitmap is a dot matrix data structure, containing columns of dots and rows, of a graphics image.
Text. Graphics Images – photos Animation Video Audio Text Copyright issues.
Zinnia Bell. RAWimages are image files that have not yet processed, they contain minimally processed data from the image sensor of either a image scanner,
Chapter 3 Adding Images in HTML. Agenda Understanding Web Page Images Prepare Your Images for the Web Insert an Image Specify an Image Size Add Alternative.
CHAPTER 1 XNA Game Studio 4.0. Your First Project A computer game is not just a program—it is also lots of other bits and pieces that make playing the.
11 Games and Content Session 4.1. Session Overview  Show how games are made up of program code and content  Find out about the content management system.
Unit 30 P1 – Hardware & Software Required For Use In Digital Graphics
Rob Miles Microsoft MVP University of Hull Fun Programming with Visual Studio.
Image Storage Bitmapped Graphics – in which an image is represented as a collection of dots Vector Graphics – in which an image is represented as a set.
Presentation Design: Graphics. More About Color “Bit depth” of colors -- This is based on the smallest unit of information that a computer understands.
Copyright © 2003 Pearson Education, Inc. Slide 4-1 Created by, Stephanie Ludi, Rochester Institute of Technology—NY Basic Web Page Construction Graphics.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Week 1 - Wednesday.  What did we talk about last time?  Syllabus  Colors  RGB  CMYK  HSL and HSV.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
CSCE Chapter 5 (Links, Images, & Multimedia) CSCE General Applications Programming Benito Mendoza 1 By Benito Mendoza Department.
Developing the Game User Interface (UI) Lesson 5.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
8 Using Web Graphics Section 8.1 Identify types of graphics Identify and compare graphic formats Describe compression schemes Section 8.2 Identify image.
Copyright © 2009 Curt Hill The Picture Object Getting and displaying.
11 Adding Sounds Session 7.1. Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
XNA An Introduction. What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Introduction to Photoshop Altering photos 1 pixel at a time.
Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is written in a programming language – C# is a programming.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Project Two Adding Web Pages, Links, and Images Define and set a home page Add pages to a Web site Describe Dreamweaver's image accessibility features.
XNA Basic Displaying Image & Collision Detect. What’s format image that XNA support? XNA support only.bmp.png and.jpg image..PNG have transparent region.
Editing Images for the Web. Optimization/Compression Graphics optimization is important for fast web page display.
Digital Images are represented by manipulating this…
Introduction to Images & Graphics JMA260. Objectives Images introduction Photoshop.
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
1 2/22/05CS120 The Information Era Chapter 4 Basic Web Page Construction TOPICS: Images and placing pages on the server.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
11 Computers, C#, XNA, and You Session 1.1. Session Overview  Find out what computers are all about ...and what makes a great programmer  Discover.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
XNA ● Proprietary Microsoft framework ● C#. Interface.
11 Using the Keyboard in XNA Session 9.1. Session Overview  Discover more detail on how the XNA keyboard is implemented  Find out how to use arrays.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Rob Miles. Using data in an XNA game program An XNA game program Draw and Update methods that are called to run the game Colours are held in XNA as four.
WEB GRAPHICS EXPLORING COMPUTER SCIENCE - LESSON 3-4.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Rob Miles. Creating a Broken MoodLight An XNA game contains game data which is used by the Draw and Update methods – Update updates the game data – Draw.
CHAPTER 5 Text XNA Game Studio 4.0. Objectives Discover how text is drawn using Microsoft XNA. Add some font resources to your XNA program. Draw some.
Getting and displaying
Exploring Computer Science - Lesson 3-4
Graphical Output Basic Images.
Using and Creating Sprites
Exploring Computer Science - Lesson 3-4
Chapter 3 Image Files © 2017 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Exploring Computer Science - Lesson 3-4
MonoGame and Windows 8.
Look at Me Mod 4 Lesson 3 Graphics Module 4- Build a Game.
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Creating Images for the Web
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Presentation transcript:

CHAPTER 4 Images XNA Game Studio 4.0

Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures are manipulated in game programs. Display your pictures on the screen. Make a better version of Color Nerve and an even groovier mood light.

Program Project: Picture Display 1. You need to get the picture that you wish to draw into your game solution so that it becomes part of the program when it is loaded into the target device. 2. You must add code to the program that fetches the image into the program when it runs. 3. You need to tell XNA where on the screen the image is to be drawn. 4. You go ahead and draw the item.

Resources and Content You need to tailor your images to fit the screen of the XNA device you are going to use. The Xbox screen is capable of showing high-resolution images. A high-resolution image is made up of a large number of dots, or pixels.

Resources and Content Make the images as small as you can. This reduces the amount of memory they consume and also reduces the work required to move them around the screen. You won’t usually need very high resolution for your games, so your pictures need be no more than 800 pixels in each direction. The Windows Phone display is available with two resolutions. 480 x 800 pixels and 320 x 480 pixels.

Images Your pictures should be in the Portable Network Graphics (PNG), Windows Bitmap (BMP), or Joint Photographic Experts Group (JPEG) format. The PNG and BMP formats are lossless, in that they always store an exact version of the image that is being held. PNG files can also have transparent regions, which is important when you want to draw one image on top of another. The JPEG format is lossy The image is compressed in a way that makes it much smaller, but at the expense of precise detail. The games that you create should use JPEG images for the large backgrounds and PNG images for the smaller objects that are drawn on top of them.

Content Management Using XNA Content = images, sounds, 3-D models, and video These content items are sometimes referred to as assets.

WORKING WITH CONTENT USING XNA GAME STUDIO XNA Game Studio 4.0

XNA Game Studio Solutions and Projects Whenever you create a project, you should ensure that the option “Create Directory For Solution” is selected. This creates a directory structure that contains the program and all the other items that are required to make the game work. You can think of a solution as a “shopping list” of projects. The solution holds a list of the names of project files. Each of the project files holds a list of the names of the files used in that project. Each item on the list is often referred to as a reference to that item, in that it tells XNA Game Studio how to get to it.

XNA Game Studio Solutions and Projects

You can write code that can be used in more than one solution. Such as a scoring project. You would do this by creating a library project. You can then add that project to your solution.

Adding Content to a Project The solution contains two projects. 1. One contains the program code and 2. the other the content that the game uses When you add an asset to the JakeDisplayContent project, it is stored in this directory

Adding Content to a Project Right-click on Content Folder. Select “Add” Select “Existing Item”

Adding Links to Resources When you add a resource using the process described previously, XNA Game Studio makes a copy of the resource and places the copy in the Content directory of the project. If you want several projects to share a single copy of a resource, you can add a link to it instead. Click the down arrow at the right of the Add button in the Add Existing Item dialog box, as shown in Figure 4-10, which allows you to add the resource as a file or as a link.

Adding Links to Resources

The XNA Content Pipeline The process of feeding resources in at one end and getting a complete game assembly out of the other is a bit like a pipeline. In fact, the XNA Framework refers to this part of the game-building process as the Content Management Pipeline.

USING RESOURCES IN A GAME XNA Game Studio 4.0

Loading XNA Textures Images that you want to draw in your games are called textures. Textures can be drawn as flat pictures, and they can also be wrapped around 3-D models. XNA provides a range of types that are used to deal with textures. The type you’ll use is called Texture2D. This holds a texture that you manipulate in two dimensions; that is, it is drawn on the screen as if it were a flat surface.

Loading XNA Textures The game data takes the form of a single variable that holds the texture. Syntax // The Game World Texture2D jakeTexture; The Draw method draws this texture on the screen. Use the Update method to make the image move around the screen by changing the draw position.

Loading XNA Textures You also can use another method that lets the program take control when the graphics need to be loaded. There is a LoadContent method that is called by XNA when a game starts running.

The LoadContent Method Loads the content that the game needs. Creates a SpriteBatch for the program to use. used to draw the texture on the screen. protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); nameTexture = this.Content.Load (“name of asset"); }

The LoadContent Method When the game starts, XNA calls the LoadContent method to fetch content for use in the game. The method then performs the statement that loads the texture content: jakeTexture = this.Content.Load ("jake"); The Load method is a kind of multipurpose tool called a generic method. Because it’s generic, it can be used to fetch any kind of item, from textures to audio files to 3-D models.

The LoadContent Method If the game had lots of different images, you would declare additional Texture2D items in your game world and assign them to textures using the LoadContent method as well.

Incorrect Asset Name Error If you get the name of the texture wrong, the game program fails in this method, as it is looking for an asset that is not there. The program fails by throwing an exception.

Positioning Your Game Sprite on the Screen A sprite is a flat, preloaded image that is used as part of a computer game. From the point of view of XNA, a sprite is an image resource along with location information that tells XNA where to draw the image. This means that you need a way to tell XNA where on the screen you want to put your sprite.

Positioning Your Game Sprite on the Screen You do this by using yet another XNA type, the Rectangle. This holds information about the position and size of a rectangle. You don’t need to worry about how a rectangle works at the moment; you need only know how to create one and set the size and position of it. The units are called pixels. Pixel, an abbreviation for “picture element,” refers to the smallest dot that can be drawn on the screen.

Positioning Your Game Sprite on the Screen Top, Left Corner (0, 0) 20 30

Positioning Your Game Sprite on the Screen A rectangle is also used to give the width and height of the sprite. XNA scales the image to fit in a rectangle. Syntax to draw your Rectangle rectName = new Rectangle (x, y, width, height) To move the image or change its size on the screen, you need to change only one of the values that is held in the rectangle. These values are members of the Rectangle structure. In C#, members that hold values are called fields.

Positioning Your Game Sprite on the Screen You can think of a field as a variable that has been declared inside a structure or class. In the case of your Game1 class, the game world data that you created (for example, the color intensity values for your mood light) are fields of that class.

The Initialize Method The Initialize method is called when the game starts up. When an XNA game runs, it goes through these steps. 1. Set things up: Initialize 2. Load game content: LoadContent 3. Repeatedly update the game and draw the display: Draw and Update 4. Free up all the content: UnloadContent

The Initialize Method Create the Rectangle object in the Initialize method. protected override void Initialize() { jakeRect = new Rectangle(30, 20, 600, 450); base.Initialize(); }

SPRITE DRAWING WITH SPRITEBATCH XNA Game Studio 4.0

Sprite Drawing with SpriteBatch A modern game console is not one powerful computer; in fact, it is several. Some of these run the game itself, whereas other special graphics processors drive the display. The graphics processor unit (GPU) contains optimized hardware to allow it to update the screen as fast as possible. When the Draw method runs, the method assembles a bunch of instructions for the GPU and sends the instructions into the GPU. The GPU then follows those instructions to put a picture on the screen.

Sprite Drawing with SpriteBatch Complex games contain many images that may be drawn at several different positions on the screen. It is important that the transfer of the position information and associated images is organized as efficiently as possible. XNA provides a special class called SpriteBatch to batch up a set of sprite-drawing instructions.

Sprite Drawing with SpriteBatch Your program calls methods on a SpriteBatch variable to get the drawing done. This means that a SpriteBatch needs to be created for the program to use. When XNA Game Studio creates a new project, it adds the statements to the LoadContent method that create a SpriteBatch for you to use. The variable is called spriteBatch. NOTE: spriteBatch & SpriteBatch are different!

Sprite Drawing with SpriteBatch You must tell spriteBatch when you’ve started drawing sprites and when you’ve finished. You call methods on the spriteBatch variable to begin the draw process, draw the sprite, and then end the drawing. protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(jakeTexture, jakeRect, Color.White); spriteBatch.End(); base.Draw(gameTime); }

Sprite Drawing with SpriteBatch spriteBatch.Draw(jakeTexture, jakeRect, Color.White); The Draw method is part of the SpriteBatch class and is given parameters that identify the image to be drawn, the rectangle to place it in, and the color of the light to “shine” on the texture.

Filling the Screen To create a Rectangle that will fill the screen. jakeRect = new Rectangle( 0, // X position of top left corner 0, // Y position of top left corner GraphicsDevice.Viewport.Width, // rectangle width GraphicsDevice.Viewport.Height); // rectangle height GraphicsDevice.Viewport.Width gets the width GraphicsDevice.Viewport.Height gets the height

Intellisense Whenever you type an identifier into the editor, it finds the Variable that the identifier represents and offers you options based on that identifier. Intellisense also shows you brief help snippets about the items that you can select.

GAME IDEA: COLOR NERVE WITH A PICTURE XNA Game Studio 4.0

Game Idea: Color Nerve with a Picture The key to this is the way that you select the color you want to use to “light” any sprite that you draw: spriteBatch.Draw(jakeTexture, jakeRect, Color.White); protected override void Draw(GameTime gameTime) { Color textureColor; textureColor = new Color(redIntensity,greenIntensity,blueIntensity); spriteBatch.Begin(); spriteBatch.Draw(jakeTexture, jakeRect, textureColor); spriteBatch.End(); base.Draw(gameTime); }