SlideShare une entreprise Scribd logo
1  sur  39
Windows Phone 7 XNA  A different kind of phone, designed for a life in motion
XNA OVerview A frameworktocreategameapplications
XNA  XNA is a framework for writing games It includes a set of professional tools for game production and resource management Windows Phone uses version 4.0 of the framework This is included as part of the Windows Phone SDK
2D and 3D games XNA provides full support for 3D games It allows a game program to make full use of the underlying hardware acceleration provided by the graphics hardware For the purpose of this course we are going to focus on 2D gaming Windows Phone games be either 2D or 3D 4
XNA and Silverlight XNA is completely different from Silverlight The way that programs are constructed and execute in XNA is quite different XNA has been optimised for game creation It does not have any elements for user interface or data binding Instead it has support for 3D rendering and game content management 5
XNA and Programs XNA provides a set of classes which allow you to create gameplay The classes represent game information and XNA resources XNA  is also a very good example of how you construct and deploy a set of software resources in a Framework
Creating a Game The Windows Phone SDK provides a Windows Phone game project type
The Game Project The solution explorer shows the items that make up our game project The solution will also contain any content that we add to the game project
Empty Game Display At the moment all our game does is display a blue screen This is because the behaviour of the Draw method in a brand new project is to clear the screen to blue
Demo 1: New Game Demo 10
What a Game Does When it Runs Initialise all the resources at the start fetch all textures, models, scripts etc Repeatedly run the game: Update the game world read the user input, update the state and position of game elements Draw the game world render the game elements on the viewing device
XNA Game Class Methods partialclassPongGame : Microsoft.Xna.Framework.Game { protectedoverridevoidLoadContent                               (boolloadAllContent)     {     } protectedoverridevoid Update(GameTimegameTime)     {     } protectedoverridevoid Draw(GameTimegameTime)     {     } }
XNA Methods and games Note that our program never calls the LoadContent, Draw and Update methods They are called by the XNA Framework  LoadContent is called when the game starts Draw is called as often as possible Update is called 30 times a second Note that this is not the same as an XNA game on Windows PC or Xbox, where Update is called 60 times a second 13
Loading Game Content protectedoverridevoidLoadContent() { // Create a new SpriteBatch, which can be used to  // draw textures. spriteBatch = newSpriteBatch(GraphicsDevice); } LoadContent is called when our game starts It is where we put the code that loads the content into our game Content includes images, sounds, models etc.
Game Content Games are not just programs, they also contain other content: Images for textures and backgrounds Sound Effects 3D Object Meshes We need to add this content to our project The XNA framework provides a content management system which is integrated into Visual Studio
Image Resources This is a Ball image I have saved it as a PNG file This allows the image to use transparency You can use any image resource you like  The resources are added to the Visual Studio project They are held in the Content directory as part of your project
Using the Content Pipeline Each resource is given an asset name  The Load method of Content Manager provides access to the resource using the Asset Name that we gave it ballTexture = Content.Load<Texture2D>("WhiteDot");
Storing the Ball Texture in the game // Game World Texture2D ballTexture; XNA provides a Texture2Dtype which holds a 2D (flat) texture to be drawn on the display The game class needs to contain a member variable to hold the ball texture that is to be drawn when the game runs This variable will be shared by all the methods in the game
Loading Content into the Ball Texture protectedoverridevoidLoadContent() { // Create a new SpriteBatch, which can be used to     // draw textures. spriteBatch = newSpriteBatch(GraphicsDevice); ballTexture = Content.Load<Texture2D>("WhiteDot"); } LoadContentis called when a game starts It loads an image into the ball texture The content manager fetches the images which are automatically sent to the target device
Making a “sprite” A sprite is an object on the screen of a game It has both a texture and a position on the screen  We are creating a sprite object for the ball in our game We now have the texture for the object The next thing to do is position it on the screen 20
Coordinates and Pixels When drawing in XNA the position of an object on the screen is given using coordinates based on pixels A standard Windows Phone screen is 800 pixels wide and 480 pixels high This gives the range of possible values for display coordinates If you draw things off the screen this does not cause XNA problems, but nothing is drawn 21
X and Y in XNA The coordinate system used by XNA sprite drawing puts the origin (0,0) in the top left hand corner of the screen Increasing X moves an object across the screen towards the right Increasing Y moves an object down the screen towards the bottom It is important that you remember this 22
Positioning the Ball using a Rectangle // Game World Texture2DballTexture; RectangleballRectangle; We can add a rectangle value to the game to manage the position of the ball on the screen We will initialise it in the LoadContent method
The Rectangle structure Rectangle ballRectangle = newRectangle(     0, 0, ballTexture.Width, ballTexture.Height), Color.White); Rectangle is a struct type which contains a position and a size The code above creates a rectangle positioned at 0,0 (top left hand corner) the same size as ballTexture We could move our ball by changing the content of the rectangle
Drawing a Sprite In game programming terms a “sprite” is a texture that can be positioned on the screen We now have a ball sprite We have the texture that contains an image of the ball We have a rectangle that gives the position and size of the sprite itself 25
XNA Game Draw Method protectedoverridevoid Draw(GameTimegameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } The Draw method is called repeatedly when an XNA game is running It has the job of drawing the display on the screen A brand new XNA game project  contains a Draw method that clears the screen to CornflowerBlue We must add our own code to the method to draw the ball
Sprite Batching 2D Graphics drawing is handled by a set of “sprite” drawing methods provided by XNA These create commands that are passed to the graphics device The graphics device will not want to draw everything on a piecemeal basis Ideally all the drawing information, textures and transformations should be provided as a single item The SpriteBatch class looks after this for us
SpriteBatch Begin and End protectedoverridevoid Draw(GameTimegameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin();     // Code that uses spriteBatch to draw the display spriteBatch.End(); base.Draw(gameTime); } The call to the Begin method tells SpriteBatch to begin a assembling a new set of drawing operations The call to the End method tells SpriteBatch that the there are no more operations and causes the rendering to take place
Using SpriteBatch.Draw spriteBatch.Draw(ballTexture, ballRectangle, Color.White); The SpriteBatch class provides a Draw method to do the sprite drawing It is given parameters to tell it what to do: Texture to draw Position (expressed as a Rectangle) Draw color
Rectangle Fun new Rectangle(   0, 0, ballTexture.Width,  ballTexture.Height) new Rectangle(   0, 0,      // position   200,100)   // size new Rectangle(   50, 50,     // position   60, 60)     // size
Demo 2: Dot Sizes Demo 31
Screen Size and Scaling We need to make our game images fit the size of the screen We can find out the size of the screen from the GraphicsDevice used to draw it GraphicsDevice.Viewport.WidthGraphicsDevice.Viewport.Height We can use this information to scale the images on the screen
Creating the ballRectangle variable ballRectangle = newRectangle(     0, 0, GraphicsDevice.Viewport.Width / 20, GraphicsDevice.Viewport.Width/ 20); If we use this rectangle to draw our ball texture it will be drawn as a square which is a twentieth of the width of the screen We can then set the position parts of the rectangle to move the ball around the screen
Moving the ball around the screen At the moment the ball is drawn in the same position each time Draw runs To move the ball around we need to make this position change over time We need to give the game an update behaviour We must add code to the Update method in the game The Update method is where we manage the state of the “game world”
The Update Method protectedoverridevoid Update(GameTimegameTime) { // TODO: Add your update logic here base.Update(gameTime); } The Update method is automatically called 30 times a second when a game is running It is in charge of managing the “game world” In a pong game this means updating the bat and the ball positions and checking for collisions
Simple Update Method protectedoverridevoid Update(GameTimegameTime) { ballRectangle.X++; ballRectangle.Y++; base.Update(gameTime); } Each time the game updates the X and Y position of the ball rectangle is increased This will cause it to move across and down the screen Note that I call the base method to allow my parent object to update too
GameTime At the moment the Update method is called sixty time a second or once every 16.66 milliseconds We can also let the update "free run", in which case we need to know the time since the last call so we can move objects the right distance This is what the GameTime parameter is for, it gives the time at which the method was called
Demo 2: Moving Dot Demo 38
Summary XNA is a Framework of methods that are used to write games You create the games using Visual Studio  Games have initialise, update and draw behaviours Game objects are held as textures objects and their position and dimensions as rectangle structures

Contenu connexe

Tendances

Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)noorcon
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)noorcon
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210Mahmoud Samir Fayed
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)noorcon
 
The Ring programming language version 1.2 book - Part 50 of 84
The Ring programming language version 1.2 book - Part 50 of 84The Ring programming language version 1.2 book - Part 50 of 84
The Ring programming language version 1.2 book - Part 50 of 84Mahmoud Samir Fayed
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)noorcon
 
The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.5.2 book - Part 49 of 181The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.5.2 book - Part 49 of 181Mahmoud Samir Fayed
 
Game Programming I - GD4N
Game Programming I - GD4NGame Programming I - GD4N
Game Programming I - GD4NFrancis Seriña
 
The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.6 book - Part 52 of 189The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.6 book - Part 52 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 74 of 196
The Ring programming language version 1.7 book - Part 74 of 196The Ring programming language version 1.7 book - Part 74 of 196
The Ring programming language version 1.7 book - Part 74 of 196Mahmoud Samir Fayed
 
Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityKobkrit Viriyayudhakorn
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.2 book - Part 48 of 181The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.2 book - Part 48 of 181Mahmoud Samir Fayed
 
Unity - Building Your First Real-Time 3D Project - All Slides
Unity - Building Your First Real-Time 3D Project - All SlidesUnity - Building Your First Real-Time 3D Project - All Slides
Unity - Building Your First Real-Time 3D Project - All SlidesNexusEdgesupport
 
The Ring programming language version 1.4.1 book - Part 19 of 31
The Ring programming language version 1.4.1 book - Part 19 of 31The Ring programming language version 1.4.1 book - Part 19 of 31
The Ring programming language version 1.4.1 book - Part 19 of 31Mahmoud Samir Fayed
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 

Tendances (20)

Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 7 (Preview)
 
The Ring programming language version 1.2 book - Part 50 of 84
The Ring programming language version 1.2 book - Part 50 of 84The Ring programming language version 1.2 book - Part 50 of 84
The Ring programming language version 1.2 book - Part 50 of 84
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
 
The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.5.2 book - Part 49 of 181The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.5.2 book - Part 49 of 181
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
 
Game Programming I - GD4N
Game Programming I - GD4NGame Programming I - GD4N
Game Programming I - GD4N
 
The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.6 book - Part 52 of 189The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.6 book - Part 52 of 189
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
 
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.1 book - Part 48 of 180
 
The Ring programming language version 1.7 book - Part 74 of 196
The Ring programming language version 1.7 book - Part 74 of 196The Ring programming language version 1.7 book - Part 74 of 196
The Ring programming language version 1.7 book - Part 74 of 196
 
3d game engine
3d game engine3d game engine
3d game engine
 
Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in Unity
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202
 
The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.2 book - Part 48 of 181The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.2 book - Part 48 of 181
 
Unity - Building Your First Real-Time 3D Project - All Slides
Unity - Building Your First Real-Time 3D Project - All SlidesUnity - Building Your First Real-Time 3D Project - All Slides
Unity - Building Your First Real-Time 3D Project - All Slides
 
The Ring programming language version 1.4.1 book - Part 19 of 31
The Ring programming language version 1.4.1 book - Part 19 of 31The Ring programming language version 1.4.1 book - Part 19 of 31
The Ring programming language version 1.4.1 book - Part 19 of 31
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 

En vedette (6)

Adobe Illustrator Tutorials: Digital Photography Flyer
Adobe Illustrator Tutorials: Digital Photography FlyerAdobe Illustrator Tutorials: Digital Photography Flyer
Adobe Illustrator Tutorials: Digital Photography Flyer
 
Multimedia system 3 rd sem 2012aug.ASSIGNMENT
Multimedia system 3 rd sem 2012aug.ASSIGNMENTMultimedia system 3 rd sem 2012aug.ASSIGNMENT
Multimedia system 3 rd sem 2012aug.ASSIGNMENT
 
File17749
File17749File17749
File17749
 
hwtut
hwtuthwtut
hwtut
 
Java 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENTJava 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENT
 
hwtut
hwtuthwtut
hwtut
 

Similaire à XNA Game Framework Overview for Windows Phone 7

The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84Mahmoud Samir Fayed
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA GameSohil Gupta
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30Mahmoud Samir Fayed
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202Mahmoud Samir Fayed
 
XNA And Silverlight
XNA And SilverlightXNA And Silverlight
XNA And SilverlightAaron King
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
98 374 Lesson 05-slides
98 374 Lesson 05-slides98 374 Lesson 05-slides
98 374 Lesson 05-slidesTracie King
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - IntroductionFrancis Seriña
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platformgoodfriday
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to UnityKoderunners
 
Beginning Game Development in XNA
Beginning Game Development in XNABeginning Game Development in XNA
Beginning Game Development in XNAguest9e9355e
 
Beginning Game Development in XNA
Beginning Game Development in XNABeginning Game Development in XNA
Beginning Game Development in XNAguest9e9355e
 
Monogame and xna
Monogame and xnaMonogame and xna
Monogame and xnaLee Stott
 
The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.6 book - Part 51 of 189The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.6 book - Part 51 of 189Mahmoud Samir Fayed
 

Similaire à XNA Game Framework Overview for Windows Phone 7 (20)

The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84
 
Galactic Wars XNA Game
Galactic Wars XNA GameGalactic Wars XNA Game
Galactic Wars XNA Game
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
 
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202
 
XNA And Silverlight
XNA And SilverlightXNA And Silverlight
XNA And Silverlight
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
Presentación Unity
Presentación UnityPresentación Unity
Presentación Unity
 
98 374 Lesson 05-slides
98 374 Lesson 05-slides98 374 Lesson 05-slides
98 374 Lesson 05-slides
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - Introduction
 
Unity 101
Unity 101Unity 101
Unity 101
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to Unity
 
Beginning Game Development in XNA
Beginning Game Development in XNABeginning Game Development in XNA
Beginning Game Development in XNA
 
Beginning Game Development in XNA
Beginning Game Development in XNABeginning Game Development in XNA
Beginning Game Development in XNA
 
Monogame and xna
Monogame and xnaMonogame and xna
Monogame and xna
 
The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.6 book - Part 51 of 189The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.6 book - Part 51 of 189
 
Vanmathy python
Vanmathy python Vanmathy python
Vanmathy python
 

Plus de MICTT Palma

Active directory ds ws2008 r2
Active directory ds ws2008 r2Active directory ds ws2008 r2
Active directory ds ws2008 r2MICTT Palma
 
Sharepoint 2010. Novedades y Mejoras.
Sharepoint 2010. Novedades y Mejoras.Sharepoint 2010. Novedades y Mejoras.
Sharepoint 2010. Novedades y Mejoras.MICTT Palma
 
¿Qué es la nube?
¿Qué es la nube?¿Qué es la nube?
¿Qué es la nube?MICTT Palma
 
Introduction to wcf solutions
Introduction to wcf solutionsIntroduction to wcf solutions
Introduction to wcf solutionsMICTT Palma
 
Introducción a web matrix
Introducción a web matrixIntroducción a web matrix
Introducción a web matrixMICTT Palma
 
WP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesWP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesMICTT Palma
 
WP7 HUB_Introducción a Visual Studio
WP7 HUB_Introducción a Visual StudioWP7 HUB_Introducción a Visual Studio
WP7 HUB_Introducción a Visual StudioMICTT Palma
 
WP7 HUB_Creando aplicaciones de Windows Phone
WP7 HUB_Creando aplicaciones de Windows PhoneWP7 HUB_Creando aplicaciones de Windows Phone
WP7 HUB_Creando aplicaciones de Windows PhoneMICTT Palma
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightMICTT Palma
 
WP7 HUB_Platform overview
WP7 HUB_Platform overviewWP7 HUB_Platform overview
WP7 HUB_Platform overviewMICTT Palma
 
WP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightWP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightMICTT Palma
 
WP7 HUB_Overview and application platform
WP7 HUB_Overview and application platformWP7 HUB_Overview and application platform
WP7 HUB_Overview and application platformMICTT Palma
 
WP7 HUB_Marketplace
WP7 HUB_MarketplaceWP7 HUB_Marketplace
WP7 HUB_MarketplaceMICTT Palma
 
WP7 HUB_Launch event WP7
WP7 HUB_Launch event WP7WP7 HUB_Launch event WP7
WP7 HUB_Launch event WP7MICTT Palma
 
WP7 HUB_Launch event Windows Azure
WP7 HUB_Launch event Windows AzureWP7 HUB_Launch event Windows Azure
WP7 HUB_Launch event Windows AzureMICTT Palma
 
WP7 HUB_Launch event introduction
WP7 HUB_Launch event introductionWP7 HUB_Launch event introduction
WP7 HUB_Launch event introductionMICTT Palma
 
Presentacion share point 2010
Presentacion share point 2010Presentacion share point 2010
Presentacion share point 2010MICTT Palma
 

Plus de MICTT Palma (20)

Active directory ds ws2008 r2
Active directory ds ws2008 r2Active directory ds ws2008 r2
Active directory ds ws2008 r2
 
Office 365
Office 365Office 365
Office 365
 
Ad ds ws2008 r2
Ad ds ws2008 r2Ad ds ws2008 r2
Ad ds ws2008 r2
 
Sharepoint 2010. Novedades y Mejoras.
Sharepoint 2010. Novedades y Mejoras.Sharepoint 2010. Novedades y Mejoras.
Sharepoint 2010. Novedades y Mejoras.
 
¿Qué es la nube?
¿Qué es la nube?¿Qué es la nube?
¿Qué es la nube?
 
Introduction to wcf solutions
Introduction to wcf solutionsIntroduction to wcf solutions
Introduction to wcf solutions
 
Introducción a web matrix
Introducción a web matrixIntroducción a web matrix
Introducción a web matrix
 
Ie9 + html5
Ie9 + html5Ie9 + html5
Ie9 + html5
 
WP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data ServicesWP7 HUB_Consuming Data Services
WP7 HUB_Consuming Data Services
 
WP7 HUB_Introducción a Visual Studio
WP7 HUB_Introducción a Visual StudioWP7 HUB_Introducción a Visual Studio
WP7 HUB_Introducción a Visual Studio
 
WP7 HUB_Creando aplicaciones de Windows Phone
WP7 HUB_Creando aplicaciones de Windows PhoneWP7 HUB_Creando aplicaciones de Windows Phone
WP7 HUB_Creando aplicaciones de Windows Phone
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con Silverlight
 
WP7 HUB_Platform overview
WP7 HUB_Platform overviewWP7 HUB_Platform overview
WP7 HUB_Platform overview
 
WP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightWP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a Silverlight
 
WP7 HUB_Overview and application platform
WP7 HUB_Overview and application platformWP7 HUB_Overview and application platform
WP7 HUB_Overview and application platform
 
WP7 HUB_Marketplace
WP7 HUB_MarketplaceWP7 HUB_Marketplace
WP7 HUB_Marketplace
 
WP7 HUB_Launch event WP7
WP7 HUB_Launch event WP7WP7 HUB_Launch event WP7
WP7 HUB_Launch event WP7
 
WP7 HUB_Launch event Windows Azure
WP7 HUB_Launch event Windows AzureWP7 HUB_Launch event Windows Azure
WP7 HUB_Launch event Windows Azure
 
WP7 HUB_Launch event introduction
WP7 HUB_Launch event introductionWP7 HUB_Launch event introduction
WP7 HUB_Launch event introduction
 
Presentacion share point 2010
Presentacion share point 2010Presentacion share point 2010
Presentacion share point 2010
 

Dernier

ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...liera silvan
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 

Dernier (20)

ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...
EmpTech Lesson 18 - ICT Project for Website Traffic Statistics and Performanc...
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 

XNA Game Framework Overview for Windows Phone 7

  • 1. Windows Phone 7 XNA A different kind of phone, designed for a life in motion
  • 2. XNA OVerview A frameworktocreategameapplications
  • 3. XNA XNA is a framework for writing games It includes a set of professional tools for game production and resource management Windows Phone uses version 4.0 of the framework This is included as part of the Windows Phone SDK
  • 4. 2D and 3D games XNA provides full support for 3D games It allows a game program to make full use of the underlying hardware acceleration provided by the graphics hardware For the purpose of this course we are going to focus on 2D gaming Windows Phone games be either 2D or 3D 4
  • 5. XNA and Silverlight XNA is completely different from Silverlight The way that programs are constructed and execute in XNA is quite different XNA has been optimised for game creation It does not have any elements for user interface or data binding Instead it has support for 3D rendering and game content management 5
  • 6. XNA and Programs XNA provides a set of classes which allow you to create gameplay The classes represent game information and XNA resources XNA is also a very good example of how you construct and deploy a set of software resources in a Framework
  • 7. Creating a Game The Windows Phone SDK provides a Windows Phone game project type
  • 8. The Game Project The solution explorer shows the items that make up our game project The solution will also contain any content that we add to the game project
  • 9. Empty Game Display At the moment all our game does is display a blue screen This is because the behaviour of the Draw method in a brand new project is to clear the screen to blue
  • 10. Demo 1: New Game Demo 10
  • 11. What a Game Does When it Runs Initialise all the resources at the start fetch all textures, models, scripts etc Repeatedly run the game: Update the game world read the user input, update the state and position of game elements Draw the game world render the game elements on the viewing device
  • 12. XNA Game Class Methods partialclassPongGame : Microsoft.Xna.Framework.Game { protectedoverridevoidLoadContent (boolloadAllContent) { } protectedoverridevoid Update(GameTimegameTime) { } protectedoverridevoid Draw(GameTimegameTime) { } }
  • 13. XNA Methods and games Note that our program never calls the LoadContent, Draw and Update methods They are called by the XNA Framework LoadContent is called when the game starts Draw is called as often as possible Update is called 30 times a second Note that this is not the same as an XNA game on Windows PC or Xbox, where Update is called 60 times a second 13
  • 14. Loading Game Content protectedoverridevoidLoadContent() { // Create a new SpriteBatch, which can be used to // draw textures. spriteBatch = newSpriteBatch(GraphicsDevice); } LoadContent is called when our game starts It is where we put the code that loads the content into our game Content includes images, sounds, models etc.
  • 15. Game Content Games are not just programs, they also contain other content: Images for textures and backgrounds Sound Effects 3D Object Meshes We need to add this content to our project The XNA framework provides a content management system which is integrated into Visual Studio
  • 16. Image Resources This is a Ball image I have saved it as a PNG file This allows the image to use transparency You can use any image resource you like The resources are added to the Visual Studio project They are held in the Content directory as part of your project
  • 17. Using the Content Pipeline Each resource is given an asset name The Load method of Content Manager provides access to the resource using the Asset Name that we gave it ballTexture = Content.Load<Texture2D>("WhiteDot");
  • 18. Storing the Ball Texture in the game // Game World Texture2D ballTexture; XNA provides a Texture2Dtype which holds a 2D (flat) texture to be drawn on the display The game class needs to contain a member variable to hold the ball texture that is to be drawn when the game runs This variable will be shared by all the methods in the game
  • 19. Loading Content into the Ball Texture protectedoverridevoidLoadContent() { // Create a new SpriteBatch, which can be used to // draw textures. spriteBatch = newSpriteBatch(GraphicsDevice); ballTexture = Content.Load<Texture2D>("WhiteDot"); } LoadContentis called when a game starts It loads an image into the ball texture The content manager fetches the images which are automatically sent to the target device
  • 20. Making a “sprite” A sprite is an object on the screen of a game It has both a texture and a position on the screen We are creating a sprite object for the ball in our game We now have the texture for the object The next thing to do is position it on the screen 20
  • 21. Coordinates and Pixels When drawing in XNA the position of an object on the screen is given using coordinates based on pixels A standard Windows Phone screen is 800 pixels wide and 480 pixels high This gives the range of possible values for display coordinates If you draw things off the screen this does not cause XNA problems, but nothing is drawn 21
  • 22. X and Y in XNA The coordinate system used by XNA sprite drawing puts the origin (0,0) in the top left hand corner of the screen Increasing X moves an object across the screen towards the right Increasing Y moves an object down the screen towards the bottom It is important that you remember this 22
  • 23. Positioning the Ball using a Rectangle // Game World Texture2DballTexture; RectangleballRectangle; We can add a rectangle value to the game to manage the position of the ball on the screen We will initialise it in the LoadContent method
  • 24. The Rectangle structure Rectangle ballRectangle = newRectangle( 0, 0, ballTexture.Width, ballTexture.Height), Color.White); Rectangle is a struct type which contains a position and a size The code above creates a rectangle positioned at 0,0 (top left hand corner) the same size as ballTexture We could move our ball by changing the content of the rectangle
  • 25. Drawing a Sprite In game programming terms a “sprite” is a texture that can be positioned on the screen We now have a ball sprite We have the texture that contains an image of the ball We have a rectangle that gives the position and size of the sprite itself 25
  • 26. XNA Game Draw Method protectedoverridevoid Draw(GameTimegameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } The Draw method is called repeatedly when an XNA game is running It has the job of drawing the display on the screen A brand new XNA game project contains a Draw method that clears the screen to CornflowerBlue We must add our own code to the method to draw the ball
  • 27. Sprite Batching 2D Graphics drawing is handled by a set of “sprite” drawing methods provided by XNA These create commands that are passed to the graphics device The graphics device will not want to draw everything on a piecemeal basis Ideally all the drawing information, textures and transformations should be provided as a single item The SpriteBatch class looks after this for us
  • 28. SpriteBatch Begin and End protectedoverridevoid Draw(GameTimegameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); // Code that uses spriteBatch to draw the display spriteBatch.End(); base.Draw(gameTime); } The call to the Begin method tells SpriteBatch to begin a assembling a new set of drawing operations The call to the End method tells SpriteBatch that the there are no more operations and causes the rendering to take place
  • 29. Using SpriteBatch.Draw spriteBatch.Draw(ballTexture, ballRectangle, Color.White); The SpriteBatch class provides a Draw method to do the sprite drawing It is given parameters to tell it what to do: Texture to draw Position (expressed as a Rectangle) Draw color
  • 30. Rectangle Fun new Rectangle( 0, 0, ballTexture.Width, ballTexture.Height) new Rectangle( 0, 0, // position 200,100) // size new Rectangle( 50, 50, // position 60, 60) // size
  • 31. Demo 2: Dot Sizes Demo 31
  • 32. Screen Size and Scaling We need to make our game images fit the size of the screen We can find out the size of the screen from the GraphicsDevice used to draw it GraphicsDevice.Viewport.WidthGraphicsDevice.Viewport.Height We can use this information to scale the images on the screen
  • 33. Creating the ballRectangle variable ballRectangle = newRectangle( 0, 0, GraphicsDevice.Viewport.Width / 20, GraphicsDevice.Viewport.Width/ 20); If we use this rectangle to draw our ball texture it will be drawn as a square which is a twentieth of the width of the screen We can then set the position parts of the rectangle to move the ball around the screen
  • 34. Moving the ball around the screen At the moment the ball is drawn in the same position each time Draw runs To move the ball around we need to make this position change over time We need to give the game an update behaviour We must add code to the Update method in the game The Update method is where we manage the state of the “game world”
  • 35. The Update Method protectedoverridevoid Update(GameTimegameTime) { // TODO: Add your update logic here base.Update(gameTime); } The Update method is automatically called 30 times a second when a game is running It is in charge of managing the “game world” In a pong game this means updating the bat and the ball positions and checking for collisions
  • 36. Simple Update Method protectedoverridevoid Update(GameTimegameTime) { ballRectangle.X++; ballRectangle.Y++; base.Update(gameTime); } Each time the game updates the X and Y position of the ball rectangle is increased This will cause it to move across and down the screen Note that I call the base method to allow my parent object to update too
  • 37. GameTime At the moment the Update method is called sixty time a second or once every 16.66 milliseconds We can also let the update "free run", in which case we need to know the time since the last call so we can move objects the right distance This is what the GameTime parameter is for, it gives the time at which the method was called
  • 38. Demo 2: Moving Dot Demo 38
  • 39. Summary XNA is a Framework of methods that are used to write games You create the games using Visual Studio Games have initialise, update and draw behaviours Game objects are held as textures objects and their position and dimensions as rectangle structures

Notes de l'éditeur

  1. Start Visual StudioSelect File&gt;New&gt;Project to open the New Project dialogSelect XNA Game Studio 4 from the list of available templates on the leftSelect Windows Phone Game (4.0) from the template selection.Change the name to PongGame.Click OK.The project will now be created.Click Run to run the project. The emulator will start and display the blue screen.Click Stop to stop the program.Close Visual Studio and return to the presentation.
  2. Open the PongGame project in Demo 2 Dot Sizes.Run the program.Rotate the emulator display so that it is landscape with the controls on the right. Explain that this is the default orientation for Windows Phone games.Open the file Game1.cs and navigate to the Draw method.Change the draw position and size of the dot in response to suggestions from the class.Try to draw the dot off the screen. Ask what will happen.Answer: XNA will just clip the display. This will work fineTry to draw a really big dot. Ask what will happen.Answer: The dot will be clipped again.Put the
  3. Open the PongGame project in Demo 2 Moving Dot.Run the program.Show that the dot moves slowly down the screen.Ask what controls the speed of movement:Answer It is the rate at which Update is called and the size of the change applied to the position of the dot.Open the file Game1.cs and navigate to the Update method.Change the code to:ballRectangle.X++;ballRectangle.X++;Ask what this would do to the game.Answer: It would cause the ball to move across the screen and not down. The ball will also move twice as fast.Make the point that the game is presently being