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.

Slides:



Advertisements
Similar presentations
Step-by-Step: Add a Graphical Hyperlink USE the Special Events Final presentation that is still open from the previous exercise. 1.Go to slide 4, and click.
Advertisements

Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
The GIMP Simple features tutorial By Mary A White.
Advanced Imaging Techniques Lumberton High Sci Vis II V
V Material obtained from a July, 2014 summer workshop in Guildford County.
Macromedia Director 8 Foundation Level Course. What is Director? Director is a challenging program for creating animation and multimedia productions for.
Getting Started: Ansoft HFSS 8.0
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
Objectives Define photo editing software
GIMP Tutorial v2.0 Boo Virk
Microsoft Office Illustrated Brief File Management Understanding.
Viewbox 4 Tutorial How to create a Template Please view this tutorial as a Slide Show in PowerPoint, because it contains animations that will not appear.
Editing Process Of Front Cover Lauren Alger I have shown screen shots of how I have put together all four of my pages for my final music magazine product.
1 Introduction to Photoshop Or Why Paint is “yesterday’s news…”
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
Lesson 3: Removing objects. Starter: Open the powerpoint from O:\ Drive 1. Double click “My Computer” on the desktop 2. Double click “O:\” 3. Double click.
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.
Chapter 3 Working with Symbols and Interactivity.
GIMP Graphic Image Manipulation Program. GIMP Image manipulation software Free Open Source Written by two students First version in 1996.
Microsoft Office 2003 Illustrated Introductory with Programs, Files, and Folders Working.
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 10 Enhancing Specific Selections. Chapter Lessons Create an alpha channel Isolate an object Erase areas in an image to enhance appearance Use.
Image processing Gladys Nzita-Mak. Input devices A mouse is used to interact with your computer, the user is able to move the mouse, click and select.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Working with Symbols and Interactivity
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.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
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.
Computer Graphics Bitmaps & Sprites CO2409 Computer Graphics Week 3.
Photoshop Teppo Räisänen LIIKE/OAMK General Information Photoshop is an advanced image editing tool Web Graphics Printed material UI is based on.
3.2. G RAPHICS I Alpha blending within games. An exploration of the use of alpha blending within games.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
© 2011 Delmar, Cengage Learning Chapter 10 Enhancing Specific Selections.
Saturday, September 16, 2006 By: April M. Bowser Photoshop 7 Session 1.
Adobe Photoshop CS Design Professional SELECTIONS ENHANCING SPECIFIC.
PowerPoint Basics Tutorial 1: Objects These tutorials will introduce you to the most basic and useful functions of Microsoft PowerPoint We’re going.
Creating a navigation bar in Fireworks. Setting up the canvas Open Fireworks and choose a canvas size big enough to fit the buttons on you are going to.
Do Now: Take out your notebook and a pen. Good Morning Do Now: Take out your notebook and a pen. Good Morning Aim: How do I Log Into my Imac computer?
PLACING AND LINKING GRAPHICS
Magnify an image to see pixels Toolbox Document Tab Zoom Level Status Bar Document Window Panels Options Bar Menu Bar.
Data Representation The storage of Text Numbers Graphics.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
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.
Pinnacle Pro Painting Program User Manual Created by: David Kwasny Chris Schulz W. Scott DePouw.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
TRANSPARENCY USING ALPHA CHANNELS. IN PHOTOSHOP MAKE AN IMAGE 512 X 512 RGB, WITH WHITE BACKGROUND ADD AN ALPHA CHANNEL.
Resources & Bitmaps Adding clip art to your application.
XNA ● Proprietary Microsoft framework ● C#. Interface.
Adobe Photoshop T.Ahlam Algharasi. Adobe Photoshop Adobe Photoshop is a seriously powerful photo and image edit ( treating and manipulation, compositing,
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.
Adobe Photoshop CS4 – Illustrated Unit A: Getting Started with Photoshop CS4.
How to Create a Power Point Presentation. Topics that will be covered: 1) Getting Started 2) Common Features 3) Working with Text 4) Working with Graphics.
Simple Sprite Sheets with Inkscape & Gimp David Cline.
The Basics. Starting out This is the icon for Photoshop. Make sure that you have it!
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.
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.
V2.2 Boo Virk GIMP Tutorial v2.2 Boo Virk
Graphical Output Basic Images.
David Meredith Aalborg University
Week 2 - Monday CS361.
Using and Creating Sprites
Introduction to Basic Interface of
Gimp Guide Mr Hall.
Working with Symbols and Interactivity
More Layers, Moving, Copying
Presentation transcript:

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 transform them How to create and use a SpriteFont for writing text to the screen How to read the keyBoard or an Xbox 360 controller The onesprite program – everything you can do with a sprite

Create transparent sprite Images are stored in rectangles To make nice sprites we need specify some areas of an image to be transparent In XNA you have to create an image with transparency before it can be used You need two images: the original image and as mask image: where areas to be opaque are coloured white and areas to be transparent are coloured black

The Photoshop way - recommended If you are making your sprite from scratch then if you choose New in Photoshop Set mode to RGB and Contents to transparent background Then you draw on a transparent background, simply save as.png image and its ready for XNA If you are using a found image then you need to select the bit of the image you want and copy it into a new transparent image and save as a.png image as above.

Use magic wand tool to select the background Choose Select|Inverse to select only the object of interest Make a new image of same size with Mode set to RGB and Contents to Transparent Copy selection into new image and save a as.png Image

The Direct X way – long winded This involves using the DirectX Texture tool and is shown for completeness

Given a sprite with a single colour background (eg Grey), called eg ship.bmp In Photoshop choose the magic wand tool and click to select background Then set foreground colour to black and paint the sprite background black Then choose Select|Inverse, change foreground colour to white and paint in the selection Save this with a new filename eg: shipalpha.bmp

Use the DirectX Texture Tool Assuming you installed the DirectX sdk you can run the directX texture tool, eg found on my system:

In the DirectX Texture tool load your original image e.g. ship.bmp Choose Format|Change Surface Format and set the new format to “Unsigned 32 bit A8R8G8B8” Choose “File|Open onto alpha channel of this texture...” and select your alpha file e.g. shipalpha.bmp – the background will now be shown in a bright colour to indicate it will be transparent

Choose File|Save and it will save the file with a.dds extension e.g. ship.dds The.dds extension is a standard DirectX/XNA file format If you add ship.dds into your game and load it then it will now display with the appropriate transparency

Add a Sprite A sprite is represented by an object of the class Texture2D Its position is represented by a Vector2 It is drawn by a SpriteBatch object – this will determine how it is drawn and if any transformations will be applied to it

Add a Sprite Inside the LoadGraphicsContent() function –The texture is loaded (in this case called myTexture) –The SpriteBatch is instantiated

Draw a Sprite The lines above are added to the draw function Drawing occurs between begin and end SpriteBlendMode.AlphaBlend enables transparency The draw function has many overloads this is the simplest

Sprite properties Sprites are generally drawn from the top left of the texture down This is not always what we want The Sprite Origin is by default the top left of the texture but it can be set to a point inside the texture e.g. the middle – which is good for intuitive scaling and rotation

Sprite properties Sprites also have a depth property This ranges from 0 (near) to 1 (far) and determines the order in which sprites will be drawn A sprite texture may be sampled using the sourceRectangle parameter – ie a subsection of the texture can be drawn

Sprite Scaling Can be done by the draw function in three ways –By specifying a single float and scaling equally in the x and y directions –By specifying a Vector2 and scaling by different amounts in x and y directions –By specifying source and destination rectangles and scaling between them

Sprites A Sprite can be drawn with rotation by specifying a single float A sprite can be draw with SpriteEffects where the effect is one of FlipHorizontally, FlipVertically or None A sprite can be drawn with a tint by specifying a colour where White signifies no tint

Sprites The overall transparency of a sprite can also be set by setting the transparency of the tint colour (see the onesprite example).

Sprite Fonts XNA has a feature to take any TrueType font on your system and make it into a bitmap font that can be used by the SpriteBatch.DrawString function Choose Project|Add|New Item … and select Spritefont Give the new font a name e.g. of the font you want to use e.g. “Lucida Console”

Sprite Fonts An XML file will come up with properties of the font like name and size etc which you can edit

Sprite Fonts Create an instance of SpriteFont as a game1 class variable You need a vector2 for the position of your text

Sprite Fonts You need to load the font in the LoadGraphicsContent() function Then call the SpriteBatch.Draw method

Reading Input You can get input from keyboard or from a wired Xbox 360 controller Just plug a 360 controller to a spare USB port on your PC and get windows to find a driver and install it Up to four controllers may be attached

The 360 Controller Controller has buttons A,X,B,Y,Start,Back, LeftShoulder, RightShoulder, LeftStick and RightStick DPad has buttons Up,Down,Left,Right Triggers are analogue, return a number between 0-1 depending on how hard they are pressed Thumbsticks are analogue returning X and Y numbers from -1 to +1 depending on position

Get input states The GamePad and Keyboard states are easy to get and use For the GamePad PlayerIndex ranges from 1-4 to support 4 GamePads

Solving the button down problem A classic problem with buttons is the situation where you want to detect one button down event and not detect another until the button has been released. This is solved in XNA by having a second GamePadState and/or KeyboardState which is set to the last gamepad or keyboard state – then you just check the button was not pressed previously

Onespritecs.cs This example shows you all the things you can do with one sprite