Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.

Slides:



Advertisements
Similar presentations
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Advertisements

Using effects within a SpriteBatch or as a post render effect
11 Reaction Timer Game Session 8.1. Session Overview  Find out how an XNA program can measure the passage of time and trigger events at certain points.
3.1. G RAPHICS I The use of images within games. Reflections and advice on the games proposed in the Week 2 Hand-in.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 Creative Commons Attribution.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Image processing Lecture 4.
Display 480x800 QVGA 320x480 HVGA Capacitive touch 4 or more contact points Camera 5 mega pixels or more Dedicated camera button Hardware buttons.
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.
Rob Miles Microsoft MVP University of Hull Fun Programming with Visual Studio.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Animation and Double-Buffering. The animation methods described here are based on standard techniques of double-buffering applicable to most high-level.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 1. Data Representation Data Representation – Why do we use binary? simplicity,
Geometric Transformations
9.3. P ARTICLE S YSTEMS Development of a particle system.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Object Oriented Design COSC 315 Fall 2014 Bridget M. Blodgett.
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.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Aaron Yuen 1 Outline 9.1Storyboarding & Charting Method for Game Design 9.2Game State in Game Development 9.3Game State Management 9.4GUI Assets for Gameplay.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
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.
CHAPTER 6 Multiplayer XNA Game Studio 4.0. Objectives Discover how to detect and use individual button-press events in a game. Learn how to create and.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Jens Krüger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization GameFX C# / DirectX 2005 The Rendering Pipeline.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
XNA ● Proprietary Microsoft framework ● C#. Interface.
Lecture 13: Raster Graphics and Scan Conversion
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.
PyGame - Unit 2 PyGame Unit – – Animation.
XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");
NMF Demo: Lee, Seung Bryan Russell Computer Demonstration.
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.
Consumer Windows Phone Emulator Phone Emulator SamplesDocumentation GuidesCommunity Packaging and Verification Tools Windows Phone Dev Tools AppHub.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
Susan Ibach | Technical Evangelist Sage Franch | Technical Evangelist.
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.
XNA 4.0 Side Scrolling.
Lecture 4 Using SpriteFonts
Graphical Output Basic Images.
Pixels, Colors and Shapes
Using and Creating Sprites
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Collision Detection.
Animated Sprites.
Side Scrolling Game Development.
Bryan Russell Computer Demonstration
Animated image sequences, fonts and image transforms
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Chapter 7 The Game Loop and Animation
Collisions with Static Objects
Presentation transcript:

Playing with Sprites

XNA Game Lifecycle

In the faceBall demo program we bounced a smiley face around the graphical display against a background image. The sprite drawing method used included three parameters: Texture2D faceTexture, Vector2 facePosition, Color.White. protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, new Rectangle(minX, minY, maxX, maxY), Color.White); spriteBatch.Draw(facesTexture, facePosition, Color.White); spriteBatch.End(); base.Draw(gameTime); } Simple Sprite Display

protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, new Rectangle(minX, minY, maxX, maxY), Color.White); spriteBatch.Draw(facesTexture, facePosition, blit, Color.White); spriteBatch.End(); base.Draw(gameTime); } Displaying a Region of a Sprite Sheet faces.bmp We can define a rectangular blitting region (we'll call it blit) that represents a region of a sprite sheet. In the demo program faceBall2.zip one of the eight faces in the sprite sheet faces.bmp is selected randomly to be displayed. The variable blit is defined as a Rectangle blit.X = 2*90, blit.Y= 1*85 if (rnd.Next(1000)>990) { i = rnd.Next(4); j = rnd.Next(2); blit.X = i * 90; blit.Y = j * 85; } Sample code placed in Update( ) method. Changes blit position when random value > Rectangle blit = new Rectangle(0, 0, 90, 85);

protected override void Draw(GameTime gameTime) { spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, new Rectangle(minX, minY, maxX, maxY), Color.White); spriteBatch.Draw(facesTexture, facePosition, blit, Color.White, spriterot, spriteorigin, spritescale, spriteeffects, 0); spriteBatch.End(); base.Draw(gameTime); } Additional Effects with Sprites Another version of spriteBatch.Draw lets us specify the rotation of the sprite, reset the point of display and center of rotation (origin) and the scale (i.e. size) of the sprite being drawn. Demo program is faceBall3.zip Texture2D facesTexture, Vector2 facePosition, Rectangle blit, Color.White, float spriterot Vector2 spriteorigin float spritescale SpriteEffects spriteeffects range of values 0.0 to 2  radians (6.28..) set the center position (and center of rotation) size of sprite is multiplied by value of spritescale defined as a float by MSDN and MS2010 help but appears to be limited to value 0.

Sprite Scale and Rotation Demo faceBall3.zip

Animated Sprites In addition to moving sprite images around in the game viewport and rotating a sprite, we can display a sequence of images for a sprite that show it changing shape or orientation. This sequence of sprite images can be loaded onto a single sprite sheet from which individual sprite images can be blitted onto the display window. The three rings (from O`Riley) sprite sheet shown here is a sequence of 48 images of an animated sprite. We will use this sprite sheet to generate an animated sprite of spinning rings in the demo project named whirlygig.zip

int count = 0; int rownum, colnum; count += 1; if (count > 47) count = 0; rownum = count / 6; colnum = count % 6; blit.X = colnum * ; blit.Y = rownum * ; Typically the sprite sheet has the image sequence in a two-dimensional pattern. We want to display each image in sequence. OK, here's the trick. You run an integer count from 0 through 1-n where n is the number of images in the sprite animation sequence. For our rings sequence there are 48 images in a 6x8 array. The sprite sheet is 476x634 pixels so each image is about 79 x 79 pixels. We need to determine the upper-left corner of each image so we will use the count to step through the rows and columns of the 2D array of images. For example when count = 34 we want the 79x79 pixel image whose upper-left corner is at X = 79 x (23 % 6) and Y = 79 x (23 / 6) (integer div) The code shown here permits is to compute the upper-left corner X,Y position of each of the 48 sprite images using the count from count=0 through count= 47. Accessing Animated Sprite Images from a 2D Sprite Sheet