Developing the Game User Interface (UI) Lesson 5.

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

Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros
Input from Controller and Keyboard in XNA Game Studio Express Game Design Experience Professor Jim Whitehead February 12, 2008 Creative Commons Attribution.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Module 3 Productivity Programs Common Features and Commands Microsoft Office 2007.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Guide to MCSE , Second Edition, Enhanced 1 Objectives Understand and use the Control Panel applets Describe the versatility of the Microsoft Management.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Visual Basic Chapter 1 Mr. Wangler.
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.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
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.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: Writing Graphical User Interfaces
IE 411/511: Visual Programming for Industrial Applications
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
ASP.NET Web Server Controls Basic Web Server Controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
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.
Computing Fundamentals Module Lesson 3 — Changing Settings and Customizing the Desktop Computer Literacy BASICS.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
11 Using the Keyboard Session Session Overview  Introduce the keyboard device  Show how keys on a keyboard can be represented by enumerated types.
XNA An Introduction. What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
11 Getting Player Input Using a Gamepad Session 3.1.
Lesson No: 6 Introduction to Windows XP CHBT-01 Basic Micro process & Computer Operation.
Topics Introduction Scene Graphs
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Building the Events Components– Lesson 111 Building the Events Components Lesson 11.
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.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Understanding Desktop Applications Lesson 5. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Windows Forms Applications Understand.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
XNA ● Proprietary Microsoft framework ● C#. Interface.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
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.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Integrating Components and Dynamic Text Boxes with the Animated Map– Lesson 101 Integrating Components and Dynamic Text Boxes with the Animated Map Lesson.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
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.
Computer Literacy BASICS
ICT Gaming Lesson 3.
Presentation transcript:

Developing the Game User Interface (UI) Lesson 5

Exam Objective Matrix Skills/ConceptsMTA Exam Objectives Managing the UI AssetsPlan for game state (3.2) Design the user interface (1.4) Capture user data (1.6) Work with XNA (1.7) Programming the UI Game States Design the user interface (1.4) Work with XNA (1.7) Programming the UI Access Mechanisms Design the user interface (1.4) Work with XNA (1.7)

Managing the UI Assets UI is a collective term used to refer to the onscreen elements through which a player interacts with the game. –The UI helps the player access information about the game world and the status of his or her character. The UI assets designed previously—such as menu, sprites, and GUI controls—need to be created or loaded in the XNA Framework before you can add code to make them functional in your game.

Loading UI Assets To access game assets at run time for immediate use, XNA Framework 4.0 provides you with the content pipeline. –The content pipeline allows you to include the necessary game assets in the form of managed code object in the game’s executable. –To make your game assets available to the content pipeline, you need to load the required asset to the game content project.

Using Solution Explorer to Add Assets

Loading Assets Into the Game Load assets into the game code by overriding the LoadContent method. protected override void LoadContent() { /* the Content.Load method loads a game asset that has been processed by the content pipeline */ Texture2D backgroundScreen = Content.Load Base.LoadContent(); }

Configuring Audio Playing a loaded audio file when a menu is displayed. protected override void LoadContent() { /* Create a new SpriteBatch, which can be used to draw textures.*/ spriteBatch = new SpriteBatch(GraphicsDevice); soundOnMenuDisplay = Content.Load sound file name”); /; }

Configuring Video First create an object of Video class to represent the file. /*Define an object for video player and video.*/ Microsoft.Xna.Framework.Media.VideoPlayer videoPlayer; Microsoft.Xna.Framework.Media.Video videoObject;

Configuring Video Next, create a VideoPlayer object to provide the player controls. /*.Initialize video player in Game.Initialize()*/ videoPlayer = new Microsoft.Xna.Framework.Media.VideoPlayer(); /*Load the media file you want to play in video player in Game.LoadContent()*/ videoObject= content.Load video file path”);

Configuring Player Inputs You can retrieve user inputs from the respective input device such as a mouse or a keyboard to map the captured data to the desired UI asset. XNA 4.0 includes all the functionalities required to capture the current state of the input devices, such as the keyboard, mouse, and joystick. –You simply need to access the specific classes and structures provided in the Microsoft.Xna.Framework.Input namespace.

Input Namespace Structures GamePadButtons –Identifies whether buttons on the Xbox controller are pressed or released GamePadCapabilities –Identifies the capabilities and type of Xbox controller GamePadState –Describes the current state of Xbox controller GamePadThumbSticks –Represents the position of left and right sticks MouseState –Represents the current state of the mouse Keyboardstate –Represents the state of keystrokes recorded by a keyboard

Detecting State of Keys 1.Declare instances of KeyboardState class to hold the last and current state value of the keyboard ( LastKeyBoardState, CurrentKeyBoardState ). 2.Assign a value to LastKeyboardState in the game constructor. 3.Call the GetState method to hold the current keyboard state. 4.Compare the values of the two keyboard states. 5.Update the LastKeyboardState to hold the current keyboard state.

Play a Sound on Keyboard Key Press /* declare an object of SoundEffect and an object of KeyboardHandler in your Game class in the XNAKeyboardHandler project */ SoundEffect soundOnKeyPressA; KeyboardHandler keyHandler; /* modify the LoadContent method as shown below */ protected override void LoadContent() { /* create a new SpriteBatch, which can be used to draw textures */ spriteBatch = new SpriteBatch(GraphicsDevice); soundOnKeyPressA = Content.Load sound file name”); }

Detecting Mouse Position 1.Call Mouse.GetState to get the current state of the mouse. 2.Use MouseState.X and MouseState.Y to get the position of the mouse in pixels.

Detecting Xbox 360 Controller State 1.Use GetState to determine the current state of the Xbox. 2.Verify whether the Xbox is connected using the IsConnected property. 3.Get the values of the buttons you want to check if pressed currently. For any button, if the value is Pressed, it means the button is currently pressed by the player.

Get Gamepad State public XNAGamePad() { / To get the state of GamePad you need PlayerIndex that specifies which GamePad’s state is queried. XBOX supports multiple GamePads at same time */ currentGamepadState = GamePad.GetState(PlayerIndex.One); } public void update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One) != currentGamepadState) { previousGamepadState = currentGamepadState; currentGamepadState = GamePad.GetState(PlayerIndex.One); }

Check For Specific Button Press /* Check for specific button press */ public bool isButtonPressed(Buttons btn ) { currentGamepadState = GamePad.GetState(PlayerIndex.One); if (currentGamepadState.IsConnected && currentGamepadState.IsButtonDown(btn)) { return true; } return false; }

Creating Menus You can use menus to provide players with a list of options. –You can use menus as part of the game story or the game space. –You can also use menus as a nondiegetic component on a welcome or opening screen, where players can select the activity they want to perform.

Menus as Drawable Game Components You can create menus as drawable game components and then add them to your game’s content solution to access it in the code. –This provides a modular approach to adding graphics content to your game. –Register the component with your game class by passing the component to the Game.Components.Add method. –Use the Game.Initialize, Game.Draw and Game.Update methods for updates.

Creating a Custom Menu 1.Create a MenuItem class to hold each menu item. 2.Create the structure to hold the menu items in the MenuComponent class item. 3.In the MenuComponent class, add the addMenuItem and CheckKey methods. Also add the update and draw methods. 4.Declare an object of MenuComponent. MenuComponent menuSystem. 5.Load the required sprite font using LoadContent and add the menu items. 6.Use the Game.Update method to add an Exit event. 7.Override the Draw method to include the sprite batches.

Creating the Custom Menu The sample code in the textbook creates a class named MenuItem to hold the information of each of the menu item, such as the item name and its position on the screen. The code then creates a DrawableGameComponent class type called MenuComponent. This MenuComponent class performs the following tasks: –Creates the list of menu items –Tracks the key press generated from the keyboard and accordingly selects a particular menu –Draws each menu item and displays the selected menu item in a different color

Examining a Custom Menu

Managing Save-Load Managing save-load involves providing the player with an option for saving and loading the game from a specific point or level. –Allows the player can replay the current level with a new inventory. –Allows the player can use to save and/or load the game from a specific point or level.

Sample Save-Load Screen

Defining UI Behavior Using States Defining the various valid states for your UI objects helps your game to decide what action to perform when in that state. –You can declare a variable to store the value of the game state at any point in the game. –The game state variable can assume Boolean values or custom-enumerated values. –The game state variable is instrumental in managing the game states.

Programming the UI Access Mechanisms Programming UI access mechanisms involve creating the required GUI controls for your game. –For example, a player can save or load a game with the click of a button or select the required tools for his inventory by selecting the options given in a check box. –GUI controls have become an integral part of game programming.

GUI Controls and Event Handlers GUI Controls Button Label Textbox Check box Radio button Picture box Form Event Handlers Mouse click Mouse enter Mouse leave Mouse move Mouse down Toggle Close Button press Key press

Example: Creating a Check Box Steps required: –Create a check box control. –Create the method that contains the code to be executed when the check box is selected. –Create an OnClick event handler that maps the check box control with its corresponding method.

Sample Checkbox Control

Recap Managing the UI Assets Loading UI Assets Using Solution Explorer to Add Assets Loading Assets Into the Game Configuring Audio Configuring Video Configuring Player Inputs Input namespace structures Detecting State of Keys Play a Sound on Keyboard Key Press Detecting Mouse Position Detecting Xbox 360 Controller State Get Gamepad State Check For Specific Button Press Creating Menus Menus as Drawable Game Components Creating a Custom Menu Managing Save-Load Defining UI Behavior Using States Programming the UI Access Mechanisms