Animated Sprites.

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

2D Platform Games: Tiles & Scrolling
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;
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
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.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 Creative Commons Attribution.
2D Graphics in XNA Game Studio Express (Plus, Random numbers in C#) Game Design Experience Professor Jim Whitehead January 16, 2009 Creative Commons Attribution.
Console I/O in C# 2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead January 14, 2009 Creative.
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett.
Display 480x800 QVGA 320x480 HVGA Capacitive touch 4 or more contact points Camera 5 mega pixels or more Dedicated camera button Hardware buttons.
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience January 14, 2010 Arnav Jhala.
AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.
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.
J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to introduce M3G; –to start talking about "M3G Chapter 2. An Animated Model" u leave the floor,
Rob Miles Microsoft MVP University of Hull Fun Programming with Visual Studio.
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.
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.
Developing the Game User Interface (UI) Lesson 5.
1 Useful Tools for Making Video Games Part V An overview of.
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience XNA Game Studio January 12, 2010 Arnav Jhala Adapted from Jim Whitehead’s slides.
9.3. P ARTICLE S YSTEMS Development of a particle system.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
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.
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.
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.
Advanced techniques for the development of 2D Windows 8 games using Direct X and C++ Markus Jost CEO, Lead Programmer, Codebox GmbH
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
Overview  Basic requirements of implementation  Image resource  Texture mapping  Advanced requirements of implementation  KGL sprite class.
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.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");
2D drawing basics For CSE 3902 By: Matt Boggus. Overview 2D coordinate systems Raster images Sprite drawing in XNA.
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.
Simple Sprite Sheets with Inkscape & Gimp David Cline.
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.
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
2D Physics and Camera Systems
Graphical Output Basic Images.
Object-Oriented Programming Concepts
Week 2 - Monday CS361.
Using and Creating Sprites
Gameprogrammeren: Klassen en objecten in Painter
Windows Phone: how to build a game
Gameprogrammeren: Menu’s in Penguin Pairs
Collision Detection.
Side Scrolling Game Development.
Animated image sequences, fonts and image transforms
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Development of a particle system
Collisions with Static Objects
Presentation transcript:

Animated Sprites

Class-Level Variables GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D panobkg; Rectangle bkg; Vector2 bkgpos; Vector2 bkgorigin; Vector2 homerpos; KeyboardState keystate; Rectangle homer; Texture2D homersprite; Random rnd = new Random(); float homerflip; Vector2 homercenter = new Vector2(28, 43); int homercount; int jumpcount; int mshomer = 60; int msdel; double y; int ybase; double vy; double ay = -0.1; SoundEffect woohoo; SoundEffect scream; SoundEffect doh; homer animation rate (60 milliseconds per frame)

SpriteSheet for Animated Sprites 742 x 174 174/2 = 87 742/13 = 57

size of blit in spritesheet protected override void Initialize() { base.Initialize(); bkgpos.X = 0; bkgpos.Y = 0; graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 348; bkg = new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); bkgorigin.X = 0; bkgorigin.Y = 0; graphics.ApplyChanges(); homer.X = 0; homer.Y = 0; homer.Width = 57; homer.Height = 87; homercount = 6; jumpcount = 0; homerflip = 0; msdel = 0; homerpos.X = graphics.PreferredBackBufferWidth / 2; homerpos.Y = graphics.PreferredBackBufferHeight - 63; ybase = (int)homerpos.Y; vy = 0.0; } size of blit in spritesheet

Homer Running msdel += gameTime.ElapsedGameTime.Milliseconds; keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.Right)) { homer.Y = 0; if (homerpos.X < bkg.Width / 2 - 43) homerpos.X += 4; else bkg.X += 4; if (bkg.X >= panobkg.Width - bkg.Width) if (msdel > mshomer) homercount -= 1; msdel = 0; if (homercount < 0) homercount = 5; } if (keystate.IsKeyDown(Keys.Left)) { homer.Y = 87; if (homerpos.X > bkg.Width / 2 + 43) homerpos.X -= 4; else bkg.X -= 4; if (bkg.X <= 0) if (msdel > mshomer) homercount -= 1; msdel = 0; if (homercount < 0) homercount = 5; }

Scrolling Background location of homer in world coordinates if (keystate.IsKeyUp(Keys.Right) && keystate.IsKeyUp(Keys.Left) && jumpcount == 0) homercount = 6; if (homerflip > 0) homerflip += (float)0.6; if (homerflip > 25) homerflip = 0; homer.X = (homercount + jumpcount) * 57; if (homerpos.X > bkg.Width - 35) homerpos.X = bkg.Width - 35; if (homerpos.X < 35) homerpos.X = 35; if (bkg.X < 0) bkg.X = 0; if (bkg.X > panobkg.Width - bkg.Width) bkg.X = panobkg.Width - bkg.Width; location of homer in world coordinates scrolling in background

Homer Jumping if (keystate.IsKeyDown(Keys.Up) && jumpcount == 0) { vy = 1.3; jumpcount = 7; homercount = 0; woohoo.Play(); } if (jumpcount > 0) vy += ay; y += vy + ay / 2.0; homerpos.Y -= (int)y; if (homerpos.Y > ybase) homerpos.Y = ybase; jumpcount = 0; vy = 0.0; y = 0.0;

location sprite is being drawn size of sprite blit protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(panobkg, bkgorigin, bkg, Color.White, 0, bkgorigin, 1, 0, 1); spriteBatch.Draw(homersprite, homerpos, homer, Color.White, homerflip, homercenter, 2, 0, 0); spriteBatch.End(); base.Draw(gameTime); } source of sprite image location sprite is being drawn size of sprite blit sprite rotation angle center of rotation