Using and Creating 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

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
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.
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
Foundation Level Course
DIGITAL GRAPHICS & ANIMATION Complete LESSON 4 ADDING TEXT TO GRAPHICS.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 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.
Fonts Typeface Typography. Leading Spacing between lines.
I can haz gamez?. Bret Stateham Microsoft Developer Evangelist Blog:
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.
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.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
CHAPTER FIVE TEXT.
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.
Adobe Fireworks CS3 Revealed CHAPTER ONE: GETTING STARTED WITH ADOBE FIREWORKS.
Macromedia Fireworks 8 Revealed MACROMEDIA FIREWORKS GETTING STARTED WITH.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Applications for Web Development (CIS 162) Intro to Photoshop.
Developing the Game User Interface (UI) Lesson 5.
1 Useful Tools for Making Video Games Part V An overview of.
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.
Digital Images Can show something that cannot be photographed Illustration- using images that represent or express to make a visual statement.
Rob Miles. Creating a Working MoodLight We know that colours in XNA are stored as values which represent the amount of red, blue, green and transparency.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
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.
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.
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
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.
11 Adding Vibration Effects Session Session Overview  Describe how the vibration feature of the gamepad works  Show how an XNA program can control.
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.
Creating cast members  Using tool palette window that can be selected from window menu.  The following objects can be created: Push buttons, Radio buttons,
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.
Section 3: Computing With Confidence. How to Become a Skilled Learner Outline: –Computing problem –Becoming a skilled learner –How to learn on your own.
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
Section 3: Computing With Confidence
Week 2 - Monday CS361.
Lesson 16 Enhancing Documents
Gameprogrammeren: Klassen en objecten in Painter
2D drawing basics For CSE 3902 By: Matt Boggus.
Tutorial: How to Creat a Website.
Collision Detection.
Animated Sprites.
Chapter Lessons Understand the Fireworks work environment
Side Scrolling Game Development.
Lecture 2 - Building a Monogame Windows Project
Animated image sequences, fonts and image transforms
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Collisions with Static Objects
Presentation transcript:

Using and Creating Sprites Lecture 3 Using and Creating Sprites Catch a Falling Star

Background Image

Simple Sprites Sprites are 2D textures that can be created using any pixel level drawing tool. Power Point can be used to create the sprite as a vector object and then be converted to a bitmap or png file by performing a copy and paste into Paint. The standard transparency color is magenta RGB = (255,0,255). Do not use compressed graphical formats such as .jpg with transparency to avoid the purple halo. This is an artifact of the blending of colors at boundaries. The smoothing reduces jaggies but those colors near magenta will not be interpreted as the transparency color.

Using SpriteFonts in MonoGame and XNA SpriteFonts are existing <?xml version="1.0" encoding="utf-8"?> <!-- This file contains an xml description of a font, and will be read by the XNA Framework Content Pipeline. Follow the comments to customize the appearance of the font in your game, and to change the characters which are available to draw with. --> <XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> <Asset Type="Graphics:FontDescription"> <!-- Modify this string to change the font that will be imported. --> <FontName>SegoeUImono</FontName> <!-- Size is a float value, measured in points. Modify this value to change the size of the font. --> <Size>12</Size> <!-- Spacing is a float value, measured in pixels. Modify this value to change the amount of spacing in between characters. --> <Spacing>0</Spacing> <!-- UseKerning controls the layout of the font. If this value is true, kerning information will be used when placing characters. --> <UseKerning>true</UseKerning> <!-- Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic", and "Bold, Italic", and are case sensitive. --> <Style>Regular</Style> <!-- If you uncomment this line, the default character will be substituted if you draw or measure text that contains characters which were not included in the font. --> <!-- <DefaultCharacter>*</DefaultCharacter> --> <!-- CharacterRegions control what letters are available in the font. Every character from Start to End will be built and made available for drawing. The default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin character set. The characters are ordered according to the Unicode standard. See the documentation for more information. --> <CharacterRegions> <CharacterRegion> <Start> </Start> <End>~</End> </CharacterRegion> </CharacterRegions> </Asset> </XnaContent> in MonoGame and XNA SpriteFonts are existing objects that you may edit In Windows OS MonoGame can convert any TrueType font into an .xnb file. (see Lecture 4 for more info)

Class-Level Variables GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D bkg; Rectangle bkgrect; SpriteFont fontgameover; SpriteFont fontgame; Vector2 timepos = new Vector2(10, 10); Vector2 scorepos = new Vector2(650, 10); Vector2 gameoverpos = new Vector2(200, 150); Song cafs; SoundEffect bloop; Texture2D star_sprite; Texture2D face_sprite; Star astar; Face aface; Color col = Color.White; KeyboardState kb; bool gotit; bool pressed; double speed = 10.0; double time2go; int score;

Initialize( ) Method protected override void Initialize() { time2go = 60.0; score = 0; gotit = false; pressed = true; astar = new Star(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, 300.0, 200.0, 3.0, -4.0); aface = new Face(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, 400.0, 240.0, 0.0, 0.0); bkgrect.X = 0; bkgrect.Y = 0; bkgrect.Width = graphics.PreferredBackBufferWidth; bkgrect.Height = graphics.PreferredBackBufferHeight; base.Initialize(); }

Managing Content protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); fontgame = Content.Load<SpriteFont>("game_font"); bkg = Content.Load<Texture2D>("starry_night"); fontgameover = Content.Load<SpriteFont>("a_font"); star_sprite = Content.Load<Texture2D>("stella"); face_sprite = Content.Load<Texture2D>("face"); bloop = Content.Load<SoundEffect>("bloop"); Vector2 gameoverpos = new Vector2(200, 150); cafs = Content.Load<Song>("como_cafs"); MediaPlayer.Volume = 0.05f; MediaPlayer.Play(cafs); }

Update( ) Method protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); kb = Keyboard.GetState(); aface.Vx = 0.0; aface.Vy = 0.0; if (kb.IsKeyDown(Keys.Left)) aface.Vx = -speed; if (kb.IsKeyDown(Keys.Right)) aface.Vx = speed; if (kb.IsKeyDown(Keys.Up)) aface.Vy = -speed; if (kb.IsKeyDown(Keys.Down)) aface.Vy = speed; if (!pressed && kb.IsKeyDown(Keys.Space)) pressed = true; if ((Math.Abs(aface.X + face_sprite.Width / 2.0 - (astar.pos.X + star_sprite.Width / 2.0)) + (Math.Abs(aface.Y + face_sprite.Height / 2.0 - (astar.pos.Y + star_sprite.Height / 2.0)))) < 50.0) gotit = true; } if (pressed && !(kb.IsKeyDown(Keys.Space))) pressed = false; if (gotit) score += 1; bloop.Play(0.02f, 1.0f, 0.0f); gotit = false; if (!gotit) astar.move(); col = Color.White; else col = Color.Orange; aface.move(); time2go -= (double)gameTime.ElapsedGameTime.Milliseconds / (double)1000.0; if (time2go < 0) MediaPlayer.Stop(); base.Update(gameTime);

Draw( ) Method protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(bkg, bkgrect, Color.White); if (time2go > 0) spriteBatch.DrawString(fontgame, "Time = " + Convert.ToString((int)time2go), timepos, Color.Yellow); spriteBatch.Draw(star_sprite, astar.pos, col); spriteBatch.Draw(face_sprite, aface.pos, col); } else spriteBatch.DrawString(fontgameover, "Game Over", gameoverpos, Color.Yellow); spriteBatch.DrawString(fontgame, "Score = " + Convert.ToString(score), scorepos, Color.Blue); spriteBatch.End(); base.Draw(gameTime);