11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.

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

Create and use your own Electronic Business Card Create and send a simple business card Traditional paper business cards have been around for a long time.
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.
Dan Waters, Academic Relations Manager, Microsoft.
1. Chapter 29 Creating Forms 3 Understanding Forms Word enables you to create fill-in forms to eliminate the need for storing pre-printed forms. Add.
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Quark QuarkXPress 4 Intermediate Level Course. Working with Master Pages The Document Layout Palette allows you to add, delete, and move document and.
PowerPoint: Tables Computer Information Technology Section 5-11 Some text and examples used with permission from: Note: We are.
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Office Illustrated Fundamentals Unit B: Understanding File Management.
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.
A First Program Using C#
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.
Finishing 2D 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.
CHAPTER 9 Introducing Microsoft Office Learning Objectives Start Office programs and explore common elements Use the Ribbon Work with files Use.
11 Finding Winners Using Arrays Session 8.2. Session Overview  Find out how the C# language makes it easy to create an array that contains multiple values.
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.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
Using a Template to Create a Resume and Sharing a Finished Document
MSOffice WORD.
Text. DO NOW Login to your computer. Go to your Google Docs document for DONOW, put todays date below where you finished last time. Make a list in order.
Developing the Game User Interface (UI) Lesson 5.
MSOffice WORD 1 Microsoft® Office 2010: Illustrated Introductory Part 1 ®
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
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.
Microsoft Office 2008 for Mac – Illustrated Unit C: Understanding File Management.
11 Using the Keyboard Session Session Overview  Introduce the keyboard device  Show how keys on a keyboard can be represented by enumerated types.
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.
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.
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. Office Excel 2007 Lab 2 Charting Worksheet Data.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
CHAPTER 3 Getting Player Input XNA Game Studio 4.0.
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 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Windows XP Lab 3 Using Applications Competencies.
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
11 Debugging Programs Session Session Overview  Create and test a method to calculate percentages  Discover how to use Microsoft Visual Studio.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
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.
Digital Media Dr. Jim Rowan ITEC 2110 Chapter 3. Roll call.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
Table of Contents I: Create an automatic TOC Get started on a table of contents A TOC may be a simple list of chapter titles, or it can include several.
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.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
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.
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.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Lecture 4 Using SpriteFonts
Chapter 13 Working with Graphics
Week 2 - Monday CS361.
Using and Creating Sprites
3.01 Apply Controls Associated With Visual Studio Form
Microsoft® Office Word 2007 Training
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Microsoft Office Illustrated Fundamentals
Presentation transcript:

11 Writing Text Session 5.1

Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts  Find out how to create font resources in an XNA program  Add a font to a game and use it to display text messages  Discover how font properties are managed and how to create different text sizes  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts  Find out how to create font resources in an XNA program  Add a font to a game and use it to display text messages  Discover how font properties are managed and how to create different text sizes Chapter 5.1: Writing Text2

Text and Computers  Early computers did not print text at all  Output was displayed by lights, or punched on paper tape  Later devices were restricted to the physical design of mechanical print heads and characters built into text displays  Only recently have computers become powerful enough to be able to manage the range of fonts and type sizes that are taken for granted today  Early computers did not print text at all  Output was displayed by lights, or punched on paper tape  Later devices were restricted to the physical design of mechanical print heads and characters built into text displays  Only recently have computers become powerful enough to be able to manage the range of fonts and type sizes that are taken for granted today Chapter 5.1: Writing Text3

Fonts  A font is a set of character designs in a particular style  There are many different font designs  Popular ones are: Arial Times New Roman Courier  A font is a set of character designs in a particular style  There are many different font designs  Popular ones are: Arial Times New Roman Courier Chapter 5.1: Writing Text4

Bitmap Fonts  In the early days of computers the font was actually a set of images, one for each character, drawn at a particular size  These bitmapped fonts were hard to scale so a font design had to be supplied in a range of sizes  In the early days of computers the font was actually a set of images, one for each character, drawn at a particular size  These bitmapped fonts were hard to scale so a font design had to be supplied in a range of sizes Chapter 5.1: Writing Text5

Vector Fonts  Characters in a vector font are created by joining dots with lines  The computer uses an equation to work out the position of each point on the character shape  This makes scaling very easy, but makes a lot of work for the computer  Characters in a vector font are created by joining dots with lines  The computer uses an equation to work out the position of each point on the character shape  This makes scaling very easy, but makes a lot of work for the computer Chapter 5.1: Writing Text6

Fonts in XNA  A font in an XNA program is an item of content  It is a bitmap font which is rendered at a particular size and then drawn as a sprite  This is so XNA games can draw text as quickly as possible  The Content Manager generates the SpriteFont resource from a Windows PC font when the program is built  This is all done automatically  A font in an XNA program is an item of content  It is a bitmap font which is rendered at a particular size and then drawn as a sprite  This is so XNA games can draw text as quickly as possible  The Content Manager generates the SpriteFont resource from a Windows PC font when the program is built  This is all done automatically Chapter 5.1: Writing Text7

Adding a Font Resource  A font resource is added in a similar way to an image  The difference is that we need to create a new item, rather than load an existing picture  This opens the “Add New Item – Content” dialog  A font resource is added in a similar way to an image  The difference is that we need to create a new item, rather than load an existing picture  This opens the “Add New Item – Content” dialog Chapter 5.1: Writing Text8

Creating a New SpriteFont  The Add New Item dialog lets you select the content you want to add  For a font select SpriteFont and click Add  The Add New Item dialog lets you select the content you want to add  For a font select SpriteFont and click Add Chapter 5.1: Writing Text9

The Added Font Resource  Once the font has been added it appears in the Content part of the solution  You can add multiple fonts if a game needs to have different sizes or styles of text  The XNA Content Manager takes care of all this automatically  Once the font has been added it appears in the Content part of the solution  You can add multiple fonts if a game needs to have different sizes or styles of text  The XNA Content Manager takes care of all this automatically Chapter 5.1: Writing Text10

Building a SpriteFont  When a game program is built, the Content Manager performs the following sequence: 1. It looks in the font resource file to find out what font to use and what sized characters are required. 2. It uses this font on the Windows PC to generate a set of bitmaps (the actual SpriteFont) and puts this into a file. 3. It copies the SpriteFont file it has produced into the right place for the game to use when it runs.  When a game program is built, the Content Manager performs the following sequence: 1. It looks in the font resource file to find out what font to use and what sized characters are required. 2. It uses this font on the Windows PC to generate a set of bitmaps (the actual SpriteFont) and puts this into a file. 3. It copies the SpriteFont file it has produced into the right place for the game to use when it runs. Chapter 5.1: Writing Text11

Configuring a SpriteFont  The font and size settings for a SpriteFont are held in the SpriteFont file  You can open this file and edit it within Microsoft Visual Studio  The file itself is held in the XML file format  The font and size settings for a SpriteFont are held in the SpriteFont file  You can open this file and edit it within Microsoft Visual Studio  The file itself is held in the XML file format Chapter 5.1: Writing Text12

What Is XML?  XML stands for “eXtensible Markup Language”  It means “Way I can put stuff into a file that you (and a computer) can understand”  It is a format that lets you give data a structure  Above I’ve created an XML file to hold high score information  XML stands for “eXtensible Markup Language”  It means “Way I can put stuff into a file that you (and a computer) can understand”  It is a format that lets you give data a structure  Above I’ve created an XML file to hold high score information Chapter 5.1: Writing Text13 Rob Miles 1500

SpriteFont XML  There are numerous font properties that you might want to change  These are the two most important ones  There are numerous font properties that you might want to change  These are the two most important ones Chapter 5.1: Writing Text14 <!— Modify this string to change the font that will be imported. --> Kootenay <!— Size is a float value, measured in points. Modify this value to change the size of the font. --> 14 <!— Modify this string to change the font that will be imported. --> Kootenay <!— Size is a float value, measured in points. Modify this value to change the size of the font. --> 14

Editing a SpriteFont Chapter 5.1: Writing Text15

Adding a SpriteFont value to the Game World  If a game needs to display text messages it needs a SpriteFont variable as part of the game world  This will be used when the characters are drawn  A SpriteFont is a bit like a Texture2D, except that it contains a set of character designs rather than a single image  It will be used with the SpriteBatch to draw text  If a game needs to display text messages it needs a SpriteFont variable as part of the game world  This will be used when the characters are drawn  A SpriteFont is a bit like a Texture2D, except that it contains a set of character designs rather than a single image  It will be used with the SpriteBatch to draw text Chapter 5.1: Writing Text16 // Game World SpriteFont font; // Game World SpriteFont font;

Loading a SpriteFont  The best place to load a SpriteFont is in the LoadContent method  The format of the load is similar to image loading  This time we ask the Load method to fetch a SpriteFont rather than a Texture2D  The best place to load a SpriteFont is in the LoadContent method  The format of the load is similar to image loading  This time we ask the Load method to fetch a SpriteFont rather than a Texture2D Chapter 5.1: Writing Text17 protected override void LoadContent() { // Create a new SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load ("SpriteFont1"); }

Drawing Text with the DrawString Method  The SpriteBatch type provides a method called DrawString which draws a string of text on the display  DrawString is told:  the font to use to draw the text  the string of text to draw  the vector identifying the position on the display to start drawing  the color to draw the text with  The SpriteBatch type provides a method called DrawString which draws a string of text on the display  DrawString is told:  the font to use to draw the text  the string of text to draw  the vector identifying the position on the display to start drawing  the color to draw the text with Chapter 5.1: Writing Text18

Vectors  A vector is a way of packaging together values that describe a particular position relative to the origin  They can be 2D (x,y) or 3D (x,y,z)  They can also be used to describe a direction  We need to create a 2D vector to position the text  The XNA type for a 2D vector is called Vector2  The above statements create a vector set to 20,30  A vector is a way of packaging together values that describe a particular position relative to the origin  They can be 2D (x,y) or 3D (x,y,z)  They can also be used to describe a direction  We need to create a 2D vector to position the text  The XNA type for a 2D vector is called Vector2  The above statements create a vector set to 20,30 Chapter 5.1: Writing Text19 Vector2 textVector = new Vector2(20, 30 );

Drawing Hello World Chapter 5.1: Writing Text20 protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); Vector2 textVector = new Vector2(20, 30 ); spriteBatch.Begin(); spriteBatch.DrawString(font, "Hello World", textVector, Color.Red); spriteBatch.End(); base.Draw(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); Vector2 textVector = new Vector2(20, 30 ); spriteBatch.Begin(); spriteBatch.DrawString(font, "Hello World", textVector, Color.Red); spriteBatch.End(); base.Draw(gameTime); }

1. Drawing Text Chapter 5.1: Writing Text21  Visual Studio creates and manages a number of folders which all hold parts of the game project  This includes a folder that contains the content for the game  Visual Studio creates and manages a number of folders which all hold parts of the game project  This includes a folder that contains the content for the game

Summary  Computers can manage character fonts as either bitmaps (an image that holds a picture of the character) or vectors (a set of lines and points that describe how to draw a character)  XNA regards a font as a set of bitmaps that have been produced by the Content Manager from a vector font when the program is built  XNA font properties are held in XML  Fonts are loaded and used by a game in a very similar way to textures  Computers can manage character fonts as either bitmaps (an image that holds a picture of the character) or vectors (a set of lines and points that describe how to draw a character)  XNA regards a font as a set of bitmaps that have been produced by the Content Manager from a vector font when the program is built  XNA font properties are held in XML  Fonts are loaded and used by a game in a very similar way to textures Chapter 5.1: Writing Text22

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the fonts on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the fonts on the display. Chapter 5.1: Writing Text23

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the fonts on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the fonts on the display. Chapter 5.1: Writing Text24

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display. Chapter 5.1: Writing Text25

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display. Chapter 5.1: Writing Text26

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display. Chapter 5.1: Writing Text27

True/False Revision Quiz  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display.  Bitmap fonts are the slowest type of font to draw.  An XNA game can only contain one font.  A vector font describes how to draw the characters.  XML is only used for SpriteFont files.  The XNA Content Manager draws the text on the display. Chapter 5.1: Writing Text28