Download presentation
Presentation is loading. Please wait.
Published byLaura Bell Modified over 8 years ago
1
XNA An Introduction
2
What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling game developers to be successful on Microsoft gaming platforms. http://www.xna.com/
3
The XNA Framework is a library Now to you get why I was making you make a class library and make calls to it??? http://msdn.microsoft.com/en- us/aa937791.aspx http://msdn.microsoft.com/en- us/aa937791.aspx
4
Where is the XNA framework? – C:\Program Files\Microsoft XNA\XNA Game Studio\v3.1\References\ Windows\x86\
5
File > New Project > Windows Game
6
How a game runs On a loop – it just keeps going and going and going and going This is different than web, console and forms applications – They are “Event” driven – They will sit and do nothing until the users interacts with them A game is running on a loop and picks up changes and updates to the state and user input along the way.
7
Anatomy Lesson 1 The main entry point is found on Program.cs You generally do not add code here
8
Game1.cs (you can change this but if you do you need to change the run code in Program.cs)
9
Anatomy Lesson 2 The Initialize method is where you can initialize any assets that do not require a GraphicsDevice to be initialized.InitializeGraphicsDevice The LoadContent method is where you load any necessary game assets such as models and textures.LoadContent 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.UnloadContent 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.Update The Draw loop is the best place to render all of your objects and backgrounds on the screen.Draw
10
When do they run? Initialize runs once on the game load Load content runs once on the game load Update and Draw run over and over and over again Unload content runs once when you exit the game
11
Without doing anything If you build and run your game now, the GraphicsDeviceManager will set up your screen size and render 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. GraphicsDeviceManager
12
What is the GraphicsDeviceManager ?GraphicsDeviceManager It is a private property (you learn what this is in OOP) of the XNA Game class There are 2 – The other one is the ContentManager
13
They are initialized in the constructor (you learn what this is in OOP)
14
This is what a game looks like initially
15
Before we run it – lets make sure we can exit This code assumes that you have a controller hooked up to your computer // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();
16
Since we don’t have a controller – lets add in an input detection from the keyboard In the Update method add this code #if !XBOX KeyboardState newState = Keyboard.GetState(); if (newState.IsKeyDown(Keys.Escape)) { this.Exit(); } #endif
17
This is what the code looks like
18
Change the background color to black
19
Now lets add a background image You will need a picture first 2D Formats you can use –.dds,.bmp,.jpg,.png,.tga Links for more info – http://www.modonize.com/Articles/102.aspx http://www.modonize.com/Articles/102.aspx – http://en.wikipedia.org/wiki/Truevision_TGA\ http://en.wikipedia.org/wiki/Truevision_TGA\ – http://graphics.ethz.ch/twiki/bin/view/GameClass/Co ntentPipeline http://graphics.ethz.ch/twiki/bin/view/GameClass/Co ntentPipeline
20
First add the image file to the content pipeline right click on content folder > add >existing item > browse and pick your image
21
Add these 2 objects at the top
22
Add this code to Load Content
23
Add this to the Draw method
24
Run it and see if it works
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.