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.

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

ROSI Express Training: Adding Additional Instructors to a Course Meeting Section.
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;
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 Creative Commons Attribution.
Microsoft ® Office PowerPoint ® 2003 Training Playing movies [Your company name] presents:
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
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.
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.
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.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
COMPUTER PROGRAMMING 2 Timers. Game Idea: Mob Reaction Timer Use a timer variable to keep track of time and a variable for each player to measure the.
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.
VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.
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.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
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 An Introduction. What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling.
Object Oriented Design COSC 315 Fall 2014 Bridget M. Blodgett.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
Programming Video Games
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.
Game Maker – Getting Started What is Game Maker?.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
2.3. A RCHITECTURAL D ESIGN I Example approach for game screen management.
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.
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 14 Classes, Objects, and Games XNA Game Studio 4.0.
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.
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
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.
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.
If you don’t have Google Earth downloaded already, you can go to to get it.
XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");
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.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
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
Graphical Output Basic Images.
Week 2 - Monday CS361.
Using and Creating Sprites
Collision Detection.
Side Scrolling Game Development.
Lecture 2 - Building a Monogame Windows Project
2.3. Architectural Design I
Introduction to PowerPoint
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Collisions with Static Objects
Presentation transcript:

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 will handle setting up your screen size and rendering a blank screen. Your game will run and update all by itself. It's up to you to insert your own code to make the game more interesting. Much of the code to start and run your game has already been written for you, and all have places for you to insert your code. The Initialize method is where you can initialize any assets that do not require a GraphicsDevice to be initialized. The LoadContent method is where you load any game assets your game needs, such as models and textures. The UnloadContent method is where any game assets can be released. Generally, no extra code is required here, as assets will be released automatically when they are no longer needed. The Update loop is the best place to update your game logic: move objects around, take player input, decide the outcome of collisions between objects, and so on. The Draw loop is the best place to render all of your objects and backgrounds on the screen.

Add a Sprite The next step is to add a graphic that can be drawn on the screen. Use a small graphics file, such as a small.bmp or.jpg file. Be creative—you can even make your own. You can even skip ahead a bit and make a sprite that "hides" parts that should not be seen (such as edges or corners) so that it looks even better. Once you have a graphic picked out on your computer, follow these steps …

Add a Sprite Make sure you can see the Solution Explorer for your project on the right side of the window. If you cannot see it, click the View menu, and then click Solution Explorer. When it appears, you will see files associated with your project in a tree structure. Inside the tree, you will see a node named Content. Right-click this node, click Add, and then click Existing Item. Browse to your graphic. If you can't see any files, make sure you change the Files of type selection box to read Texture Files. Click the graphic file, then click Add. An entry for the graphic file will appear in Solution Explorer. When you add a graphic file, it is automatically added to the XNA Framework Content Pipeline, which will allow you to quickly and easily load the graphic into your game. Click the entry for the graphic in the Solution Explorer. If you do not see the entry, ensure the Content node is expanded by clicking the small plus sign (+) to the left of the node, then click on the entry that appears underneath the Content node. In the Properties window below Solution Explorer, look for the "Asset Name" property. Note the name; you'll use it in your code to load the graphic so it can be displayed in your game. If the Properties window is not visible, press F4, or click the View menu, and then click Properties Window. Now, you must write code that loads and displays the sprite on the screen.

The LoadContent( ) function // This is a texture we can render. Texture2D myTexture; // Set the coordinates to draw the sprite at. Vector2 spritePosition = Vector2.Zero; protected override void LoadContent( ) { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); myTexture = Content.Load ("mytexture"); }

The Draw( ) function protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteBlendMode.AlphaBlend); spriteBatch.Draw(myTexture, spritePosition, Color.White); spriteBatch.End(); base.Draw(gameTime); }

Make the Sprite Bounce and Move // Store some information about the sprite's motion. Vector2 spriteSpeed = new Vector2( 50.0f, 50.0f ); protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // Move the sprite around. UpdateSprite(gameTime); base.Update(gameTime); }

Make the Sprite Bounce and Move void UpdateSprite(GameTime gameTime) { // Move the sprite by speed, scaled by elapsed time. spritePosition += spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; int MaxX = graphics.GraphicsDevice.Viewport.Width - myTexture.Width; int MinX = 0; int MaxY = graphics.GraphicsDevice.Viewport.Height - myTexture.Height; int MinY = 0; // Check for bounce. if (spritePosition.X > MaxX) { spriteSpeed.X *= -1; spritePosition.X = MaxX; } else if (spritePosition.X < MinX) { spriteSpeed.X *= -1; spritePosition.X = MinX; } if (spritePosition.Y > MaxY) { spriteSpeed.Y *= -1; spritePosition.Y = MaxY; } else if (spritePosition.Y < MinY) { spriteSpeed.Y *= -1; spritePosition.Y = MinY; }