SlideShare una empresa de Scribd logo
1 de 98
Descargar para leer sin conexión
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2011, 2012, 2013, 2014
XNA Game Development
L09 – 2D Graphics and Particle Engines
2D Graphics
2D Graphics Topics
• Introduction to 2D Graphics
• SpriteBatches
• Drawing Text with SpriteFonts
• Texure Atlases
• Rotating Sprites
• Additive Blending with Sprites
• 2D Particle Engines
2D World - Intro
SpriteBatch
SpriteBatch
• Create a Place to Store the Images In Game
private Texture2D background;
private Texture2D shuttle;
private Texture2D earth;
SpriteBatch
• Create a Place to Store the Images In Game
• LoadContent() method
private Texture2D background;
private Texture2D shuttle;
private Texture2D earth;
background = Content.Load<Texture2D>("stars");
shuttle = Content.Load<Texture2D>("shuttle");
earth = Content.Load<Texture2D>("earth");
Textures,
Content
Textures,
Content
SpriteBatch
• SpriteBatches Declaration
SpriteBatch spriteBatch;
SpriteBatch
• SpriteBatches Declaration
• Initializing in LoadContent()
SpriteBatch spriteBatch;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
SpriteBatch
• Drawing with SpriteBatches
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.End();
SpriteBatch
• Drawing with SpriteBatches
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.End();
SpriteBatch
• A Few More Sprites
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.Draw(earth, new Vector2(400, 250), Color.White);
spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White);
spriteBatch.End();
SpriteBatch
• A Few More Sprites
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.Draw(earth, new Vector2(400, 250), Color.White);
spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White);
spriteBatch.End();
SpriteBatch
• A Few More Sprites
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
spriteBatch.Draw(earth, new Vector2(400, 250), Color.White);
spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White);
spriteBatch.End();
You can find this in
“App1-SimpleTextures”
Going on with 2D!
Acquiring Fonts
• Making a SpriteFont
Acquiring Fonts
• Down at about line 14 in the new created file you will see the following:
• You can use any font you want that’s installed in your system
• Fonts can be installed by dragging the font file to your Fonts folder, which is
located in C:/Windows/Fonts
<FontName>Segoe UI Mono</FontName>
Acquiring Fonts
• Down at about line 14 in the new created file you will see the following:
<FontName>Segoe UI Mono</FontName>
Acquiring Fonts
• Down at about line 14 in the new created file you will see the following:
• Also look down at line 20, where it says:
<FontName>Segoe UI Mono</FontName>
<Size>14</Size>
Acquiring Fonts – the using of
• Global Scope
private SpriteFont font;
private int score = 0;
Acquiring Fonts – the using of
• Global Scope
• LoadContent()
private SpriteFont font;
private int score = 0;
font = Content.Load<SpriteFont>("Score"); // Use the name of your font here instead of 'Score'.
Acquiring Fonts – the using of
• Global Scope
• LoadContent()
• Draw()
private SpriteFont font;
private int score = 0;
font = Content.Load<SpriteFont>("Score"); // Use the name of your font here instead of 'Score'.
spriteBatch.Begin();
spriteBatch.DrawString(font, "Score", new Vector2(100, 100), Color.Black);
spriteBatch.End();
Acquiring Fonts – the using of
Acquiring Fonts – the using of
• Enhancing visual with Update() method
Acquiring Fonts – the using of
• Enhancing visual with Update() method
score++;
Acquiring Fonts – the using of
• Enhancing visual with Update() method
• Now let's replace our original spriteBatch.DrawString() line with the following:
score++;
spriteBatch.DrawString(font, "Score: " + score, new Vector2(100, 100), Color.Black);
Acquiring Fonts – the using of
• “App2-ShowingText”
Texture Atlases
Texture Atlases
Texture Atlases
Texture Atlases
• Creating an AnimatedSprite Class
• Class scope members
public class AnimatedSprite
public Texture2D Texture { get; set; }
public int Rows { get; set; }
public int Columns { get; set; }
private int currentFrame;
private int totalFrames;
Texture Atlases
• Update() method
public void Update()
{
currentFrame++;
if (currentFrame == totalFrames)
currentFrame = 0;
}
Texture Atlases
• Draw() method
public void Draw(SpriteBatch spriteBatch, Vector2 location)
{
int width = Texture.Width / Rows;
int height = Texture.Height / Columns;
int row = (int)((float)currentFrame / (float)Columns);
int column = currentFrame % Columns;
Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height);
spriteBatch.Begin();
spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
spriteBatch.End();
}
Texture Atlases
• Draw() method
public void Draw(SpriteBatch spriteBatch, Vector2 location)
{
int width = Texture.Width / Rows;
int height = Texture.Height / Columns;
int row = (int)((float)currentFrame / (float)Columns);
int column = currentFrame % Columns;
Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height);
spriteBatch.Begin();
spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
spriteBatch.End();
}
Texture Atlases
• Draw() method
public void Draw(SpriteBatch spriteBatch, Vector2 location)
{
int width = Texture.Width / Rows;
int height = Texture.Height / Columns;
int row = (int)((float)currentFrame / (float)Columns);
int column = currentFrame % Columns;
Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height);
Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height);
spriteBatch.Begin();
spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
spriteBatch.End();
}
Texture Atlases
• Now, in Game1 Class there’s just two calls!
Texture Atlases
• Now, in Game1 Class there’s just two calls!
Texture Atlases
• Now, in Game1 Class there’s just two calls!
Texture Atlases
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
animatedSprite.Update();
base.Update(gameTime);
}
Texture Atlases
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
animatedSprite.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
animatedSprite.Draw(spriteBatch, new Vector2(400, 200));
base.Draw(gameTime);
}
Texture Atlases
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
animatedSprite.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
animatedSprite.Draw(spriteBatch, new Vector2(400, 200));
base.Draw(gameTime);
}
Texture Atlases
• “App3-AnimatedSprite”
Rotating Sprites
Rotating Sprites
• Preparing the Content
private Texture2D arrow;
private float angle = 0;
Rotating Sprites
• Preparing the Content
private Texture2D arrow;
private float angle = 0;
Rotating Sprites
• Preparing the Content
• In LoadContent() method
• In Update() method
private Texture2D arrow;
private float angle = 0;
// use the name of your texture here, if you are using your own
arrow = Content.Load<Texture2D>("arrow");
angle += 0.01f;
Rotating Sprites
• Draw() Method
spriteBatch.Begin();
Vector2 location = new Vector2(400, 240);
Rectangle sourceRectangle = new Rectangle(0, 0, arrow.Width,
arrow.Height);
Vector2 origin = new Vector2(0, 0);
spriteBatch.Draw(arrow, location, sourceRectangle, Color.White,
angle, origin, 1.0f, SpriteEffects.None, 1);
spriteBatch.End();
Rotating Sprites
• Draw() Method
Rotating Sprites
• Compile and run and c it!
• “App3-RotatingSpriteV0.1”
Rotating Sprites
• It’s not what we need!
Rotating Sprites
• It’s not what we need!
• We need a“Center Point Rotation”!
Using a Center Point for Rotation
• In Draw(), change
Vector2 origin = new Vector2(0, 0);
Vector2 origin = new Vector2(arrow.Width / 2, arrow.Height);
• To
Using a Center Point for Rotation
• Compile and run
Using a Center Point for Rotation
• Compile and run
Particle Engines
The Concept
2D Particle Engine
2D Particle Engine
• Introduction
2D
Particle
Engine
2D Particle Engine
• images
2D Particle Engine
• Anatomy of a Particle Engine
2D Particle Engine
• Anatomy of a Particle Engine
– particles,
2D Particle Engine
• Anatomy of a Particle Engine
– particles,
– particle emitter,
2D Particle Engine
• Anatomy of a Particle Engine
– particles,
– particle emitter,
– the engine itself
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity
– particle emitter,
– the engine itself
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter,
– the engine itself
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter
• Location that the particles are coming from
– the engine itself
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter
• Location that the particles are coming from
• Responsible for determining how many particles will be created at any given time
– the engine itself
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter
• Location that the particles are coming from
• Responsible for determining how many particles will be created at any given time
– the engine itself
• Manages the state of the previous two components
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter
• Location that the particles are coming from
• Responsible for determining how many particles will be created at any given time
– the engine itself
• Manages the state of the previous two components
• Responsible for removing dead particles from the system
2D Particle Engine
• Anatomy of a Particle Engine
– particles
• Velocity, Angles
– particle emitter
• Location that the particles are coming from
• Responsible for determining how many particles will be created at any given time
– the engine itself
• Manages the state of the previous two components
• Responsible for removing dead particles from the system.
2D Particle Engine
• Particle
Public class Particle
2D Particle Engine
• Particle
• ParticleEngine2D
Public class Particle
Public class ParticleEngine2D
2D Particle Engine
• Particle
Public class Particle
2D Particle Engine
• Particle
• The Particle's Properties
Public class Particle
2D Particle Engine
Public class Particle
public Texture2D Texture { get; set; }
public Vector2 Position { get; set; }
public Vector2 Velocity { get; set; }
public float Angle { get; set; }
public float AngularVelocity { get; set; }
public Color Color { get; set; }
public float Size { get; set; }
public int TTL { get; set; }
• Particle
• The Particle's Properties
2D Particle Engine
• Particle
• The Particle's Properties
Public class Particle
public Texture2D Texture { get; set; }
public Vector2 Position { get; set; }
public Vector2 Velocity { get; set; }
public float Angle { get; set; }
public float AngularVelocity { get; set; }
public Color Color { get; set; }
public float Size { get; set; }
public int TTL { get; set; }
2D Particle Engine
• Particle
• The Particle's Properties
Public class Particle
public Texture2D Texture { get; set; }
public Vector2 Position { get; set; }
public Vector2 Velocity { get; set; }
public float Angle { get; set; }
public float AngularVelocity { get; set; }
public Color Color { get; set; }
public float Size { get; set; }
public int TTL { get; set; }
2D Particle Engine
• Update()
2D Particle Engine
• Update()
public void Update()
{
TTL--;
Position += Velocity;
Angle += AngularVelocity;
}
2D Particle Engine
• Update()
public void Update()
{
TTL--;
Position += Velocity;
Angle += AngularVelocity;
}
2D Particle Engine
• Draw()
public void Draw(SpriteBatch spriteBatch)
{
Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
spriteBatch.Draw(Texture, Position, sourceRectangle, Color,
Angle, origin, Size, SpriteEffects.None, 0f);
}
2D Particle Engine
• Particle
• ParticleEngine2D
Public class Particle
Public class ParticleEngine2D
2D Particle Engine
Public class ParticleEngine2D
2D Particle Engine
Public class ParticleEngine2D
• Properties
private Random random;
public Vector2 EmitterLocation { get; set; }
private List<Particle> particles;
private List<Texture2D> textures;
2D Particle Engine
public void Update()
{
int total = 10;
for (int i = 0; i < total; i++)
{
particles.Add(GenerateNewParticle());
}
for (int particle = 0; particle < particles.Count; particle++)
{
particles[particle].Update();
if (particles[particle].TTL <= 0)
{
particles.RemoveAt(particle);
particle--;
}
}
}
2D Particle Engine
public void Update()
{
int total = 10;
for (int i = 0; i < total; i++)
{
particles.Add(GenerateNewParticle());
}
for (int particle = 0; particle < particles.Count; particle++)
{
particles[particle].Update();
if (particles[particle].TTL <= 0)
{
particles.RemoveAt(particle);
particle--;
}
}
}
2D Particle Engine
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
for (int index = 0; index < particles.Count; index++)
{
particles[index].Draw(spriteBatch);
}
spriteBatch.End();
}
2D Particle Engine
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
for (int index = 0; index < particles.Count; index++)
{
particles[index].Draw(spriteBatch);
}
spriteBatch.End();
}
2D Particle Engine
• Game1 calling
2D Particle Engine
• In Update()
• In Draw()
2D Particle Engine
• In Update()
• In Draw()
particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
particleEngine.Update();
2D Particle Engine
• In Update()
• In Draw()
particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
particleEngine.Update();
particleEngine.Draw(spriteBatch);
2D Particle Engine
• In Update()
• In Draw()
particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
particleEngine.Update();
particleEngine.Draw(spriteBatch);
2D Particle Engine
• Test it, Very nice!
• Can easily be ported to windows phone!
– Visit my mobile crash course on slideshare / Windows Phone slide:
http://www.slideshare.net/ZGTRZGTR/mobile-software-engineering-crash-course-c06-windowsphone/
• App-2DParticleEngines
• You can test it on Windows Mobile!

Más contenido relacionado

La actualidad más candente

Image recognition applications and dataset preparation - DevFest Baghdad 2018
Image recognition applications and dataset preparation - DevFest Baghdad 2018Image recognition applications and dataset preparation - DevFest Baghdad 2018
Image recognition applications and dataset preparation - DevFest Baghdad 2018Husam Aamer
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysGilbert Guerrero
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185Mahmoud Samir Fayed
 
Stamps - a better way to object composition
Stamps - a better way to object compositionStamps - a better way to object composition
Stamps - a better way to object compositionVasyl Boroviak
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212Mahmoud Samir Fayed
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"Austin Zheng
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 
The Ring programming language version 1.7 book - Part 49 of 196
The Ring programming language version 1.7 book - Part 49 of 196The Ring programming language version 1.7 book - Part 49 of 196
The Ring programming language version 1.7 book - Part 49 of 196Mahmoud Samir Fayed
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in SwiftNetguru
 
Willustrator
WillustratorWillustrator
Willustrator2da
 

La actualidad más candente (20)

Image recognition applications and dataset preparation - DevFest Baghdad 2018
Image recognition applications and dataset preparation - DevFest Baghdad 2018Image recognition applications and dataset preparation - DevFest Baghdad 2018
Image recognition applications and dataset preparation - DevFest Baghdad 2018
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + Arrays
 
Chaco Step-by-Step
Chaco Step-by-StepChaco Step-by-Step
Chaco Step-by-Step
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185
 
Stamps - a better way to object composition
Stamps - a better way to object compositionStamps - a better way to object composition
Stamps - a better way to object composition
 
2011 11-mozcamp
2011 11-mozcamp2011 11-mozcamp
2011 11-mozcamp
 
modm
modmmodm
modm
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
JavaScript Obfuscation
JavaScript ObfuscationJavaScript Obfuscation
JavaScript Obfuscation
 
The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"
 
Canvas al ajillo
Canvas al ajilloCanvas al ajillo
Canvas al ajillo
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
The Ring programming language version 1.7 book - Part 49 of 196
The Ring programming language version 1.7 book - Part 49 of 196The Ring programming language version 1.7 book - Part 49 of 196
The Ring programming language version 1.7 book - Part 49 of 196
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 
Willustrator
WillustratorWillustrator
Willustrator
 

Destacado

Raster Scan And Random Scan
Raster Scan And Random ScanRaster Scan And Random Scan
Raster Scan And Random ScanDevika Rangnekar
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displaysSomya Bagai
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphicsAaina Katyal
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysSaravana Priya
 
Parts of a Computer
Parts of a ComputerParts of a Computer
Parts of a ComputerMatt Shea
 
basics of computer system ppt
basics of computer system pptbasics of computer system ppt
basics of computer system pptSuaj
 

Destacado (7)

A View of 3D PLE
A View of 3D PLEA View of 3D PLE
A View of 3D PLE
 
Raster Scan And Random Scan
Raster Scan And Random ScanRaster Scan And Random Scan
Raster Scan And Random Scan
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displays
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphics
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan Displays
 
Parts of a Computer
Parts of a ComputerParts of a Computer
Parts of a Computer
 
basics of computer system ppt
basics of computer system pptbasics of computer system ppt
basics of computer system ppt
 

Similar a XNA L09–2D Graphics and Particle Engines

How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 Mohammad Shaker
 
Getting Started with CoreGraphics
Getting Started with CoreGraphicsGetting Started with CoreGraphics
Getting Started with CoreGraphicsXamarin
 
Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Pedro Veloso
 
Adventures In Data Compilation
Adventures In Data CompilationAdventures In Data Compilation
Adventures In Data CompilationNaughty Dog
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019UA Mobile
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Eugene Kurko
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to CodingFabio506452
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and textureboybuon205
 
Opensource gis development - part 3
Opensource gis development - part 3Opensource gis development - part 3
Opensource gis development - part 3Andrea Antonello
 
Creating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartCreating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartDavid Keener
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slidestamillarasan
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesEdgar Gonzalez
 
Visual sedimentation - IEEE VIS 2013 Atlanta
Visual sedimentation - IEEE VIS 2013 AtlantaVisual sedimentation - IEEE VIS 2013 Atlanta
Visual sedimentation - IEEE VIS 2013 AtlantaSamuel Huron
 

Similar a XNA L09–2D Graphics and Particle Engines (20)

How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1
 
Getting Started with CoreGraphics
Getting Started with CoreGraphicsGetting Started with CoreGraphics
Getting Started with CoreGraphics
 
Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Adventures In Data Compilation
Adventures In Data CompilationAdventures In Data Compilation
Adventures In Data Compilation
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
OOP v3
OOP v3OOP v3
OOP v3
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
 
Opensource gis development - part 3
Opensource gis development - part 3Opensource gis development - part 3
Opensource gis development - part 3
 
Creating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChartCreating Dynamic Charts With JFreeChart
Creating Dynamic Charts With JFreeChart
 
Maps
MapsMaps
Maps
 
XNA coding series
XNA coding seriesXNA coding series
XNA coding series
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and Techniques
 
Visual sedimentation - IEEE VIS 2013 Atlanta
Visual sedimentation - IEEE VIS 2013 AtlantaVisual sedimentation - IEEE VIS 2013 Atlanta
Visual sedimentation - IEEE VIS 2013 Atlanta
 

Más de Mohammad Shaker

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian GraduateMohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyMohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesMohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - ColorMohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - TypographyMohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingMohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and ThreadingMohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsMohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and GamingMohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / ParseMohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesMohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and AdaptersMohammad Shaker
 

Más de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Último

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

XNA L09–2D Graphics and Particle Engines

  • 1. Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L09 – 2D Graphics and Particle Engines
  • 3. 2D Graphics Topics • Introduction to 2D Graphics • SpriteBatches • Drawing Text with SpriteFonts • Texure Atlases • Rotating Sprites • Additive Blending with Sprites • 2D Particle Engines
  • 4. 2D World - Intro
  • 6. SpriteBatch • Create a Place to Store the Images In Game private Texture2D background; private Texture2D shuttle; private Texture2D earth;
  • 7. SpriteBatch • Create a Place to Store the Images In Game • LoadContent() method private Texture2D background; private Texture2D shuttle; private Texture2D earth; background = Content.Load<Texture2D>("stars"); shuttle = Content.Load<Texture2D>("shuttle"); earth = Content.Load<Texture2D>("earth");
  • 11. SpriteBatch • SpriteBatches Declaration • Initializing in LoadContent() SpriteBatch spriteBatch; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here }
  • 12. SpriteBatch • Drawing with SpriteBatches spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White); spriteBatch.End();
  • 13. SpriteBatch • Drawing with SpriteBatches spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White); spriteBatch.End();
  • 14. SpriteBatch • A Few More Sprites spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White); spriteBatch.Draw(earth, new Vector2(400, 250), Color.White); spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White); spriteBatch.End();
  • 15. SpriteBatch • A Few More Sprites spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White); spriteBatch.Draw(earth, new Vector2(400, 250), Color.White); spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White); spriteBatch.End();
  • 16. SpriteBatch • A Few More Sprites spriteBatch.Begin(); spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White); spriteBatch.Draw(earth, new Vector2(400, 250), Color.White); spriteBatch.Draw(shuttle, new Vector2(450, 250), Color.White); spriteBatch.End(); You can find this in “App1-SimpleTextures”
  • 19. Acquiring Fonts • Down at about line 14 in the new created file you will see the following: • You can use any font you want that’s installed in your system • Fonts can be installed by dragging the font file to your Fonts folder, which is located in C:/Windows/Fonts <FontName>Segoe UI Mono</FontName>
  • 20. Acquiring Fonts • Down at about line 14 in the new created file you will see the following: <FontName>Segoe UI Mono</FontName>
  • 21. Acquiring Fonts • Down at about line 14 in the new created file you will see the following: • Also look down at line 20, where it says: <FontName>Segoe UI Mono</FontName> <Size>14</Size>
  • 22. Acquiring Fonts – the using of • Global Scope private SpriteFont font; private int score = 0;
  • 23. Acquiring Fonts – the using of • Global Scope • LoadContent() private SpriteFont font; private int score = 0; font = Content.Load<SpriteFont>("Score"); // Use the name of your font here instead of 'Score'.
  • 24. Acquiring Fonts – the using of • Global Scope • LoadContent() • Draw() private SpriteFont font; private int score = 0; font = Content.Load<SpriteFont>("Score"); // Use the name of your font here instead of 'Score'. spriteBatch.Begin(); spriteBatch.DrawString(font, "Score", new Vector2(100, 100), Color.Black); spriteBatch.End();
  • 25. Acquiring Fonts – the using of
  • 26. Acquiring Fonts – the using of • Enhancing visual with Update() method
  • 27. Acquiring Fonts – the using of • Enhancing visual with Update() method score++;
  • 28. Acquiring Fonts – the using of • Enhancing visual with Update() method • Now let's replace our original spriteBatch.DrawString() line with the following: score++; spriteBatch.DrawString(font, "Score: " + score, new Vector2(100, 100), Color.Black);
  • 29. Acquiring Fonts – the using of • “App2-ShowingText”
  • 33. Texture Atlases • Creating an AnimatedSprite Class • Class scope members public class AnimatedSprite public Texture2D Texture { get; set; } public int Rows { get; set; } public int Columns { get; set; } private int currentFrame; private int totalFrames;
  • 34. Texture Atlases • Update() method public void Update() { currentFrame++; if (currentFrame == totalFrames) currentFrame = 0; }
  • 35. Texture Atlases • Draw() method public void Draw(SpriteBatch spriteBatch, Vector2 location) { int width = Texture.Width / Rows; int height = Texture.Height / Columns; int row = (int)((float)currentFrame / (float)Columns); int column = currentFrame % Columns; Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height); Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height); spriteBatch.Begin(); spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White); spriteBatch.End(); }
  • 36. Texture Atlases • Draw() method public void Draw(SpriteBatch spriteBatch, Vector2 location) { int width = Texture.Width / Rows; int height = Texture.Height / Columns; int row = (int)((float)currentFrame / (float)Columns); int column = currentFrame % Columns; Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height); Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height); spriteBatch.Begin(); spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White); spriteBatch.End(); }
  • 37. Texture Atlases • Draw() method public void Draw(SpriteBatch spriteBatch, Vector2 location) { int width = Texture.Width / Rows; int height = Texture.Height / Columns; int row = (int)((float)currentFrame / (float)Columns); int column = currentFrame % Columns; Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height); Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height); spriteBatch.Begin(); spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White); spriteBatch.End(); }
  • 38. Texture Atlases • Now, in Game1 Class there’s just two calls!
  • 39. Texture Atlases • Now, in Game1 Class there’s just two calls!
  • 40. Texture Atlases • Now, in Game1 Class there’s just two calls!
  • 41. Texture Atlases protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); animatedSprite.Update(); base.Update(gameTime); }
  • 42. Texture Atlases protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); animatedSprite.Update(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); animatedSprite.Draw(spriteBatch, new Vector2(400, 200)); base.Draw(gameTime); }
  • 43. Texture Atlases protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); animatedSprite.Update(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); animatedSprite.Draw(spriteBatch, new Vector2(400, 200)); base.Draw(gameTime); }
  • 46. Rotating Sprites • Preparing the Content private Texture2D arrow; private float angle = 0;
  • 47. Rotating Sprites • Preparing the Content private Texture2D arrow; private float angle = 0;
  • 48. Rotating Sprites • Preparing the Content • In LoadContent() method • In Update() method private Texture2D arrow; private float angle = 0; // use the name of your texture here, if you are using your own arrow = Content.Load<Texture2D>("arrow"); angle += 0.01f;
  • 49. Rotating Sprites • Draw() Method spriteBatch.Begin(); Vector2 location = new Vector2(400, 240); Rectangle sourceRectangle = new Rectangle(0, 0, arrow.Width, arrow.Height); Vector2 origin = new Vector2(0, 0); spriteBatch.Draw(arrow, location, sourceRectangle, Color.White, angle, origin, 1.0f, SpriteEffects.None, 1); spriteBatch.End();
  • 50.
  • 51.
  • 53. Rotating Sprites • Compile and run and c it! • “App3-RotatingSpriteV0.1”
  • 54. Rotating Sprites • It’s not what we need!
  • 55. Rotating Sprites • It’s not what we need! • We need a“Center Point Rotation”!
  • 56. Using a Center Point for Rotation • In Draw(), change Vector2 origin = new Vector2(0, 0); Vector2 origin = new Vector2(arrow.Width / 2, arrow.Height); • To
  • 57. Using a Center Point for Rotation • Compile and run
  • 58. Using a Center Point for Rotation • Compile and run
  • 61. 2D Particle Engine • Introduction
  • 64. 2D Particle Engine • Anatomy of a Particle Engine
  • 65. 2D Particle Engine • Anatomy of a Particle Engine – particles,
  • 66. 2D Particle Engine • Anatomy of a Particle Engine – particles, – particle emitter,
  • 67. 2D Particle Engine • Anatomy of a Particle Engine – particles, – particle emitter, – the engine itself
  • 68. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity – particle emitter, – the engine itself
  • 69. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter, – the engine itself
  • 70. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter • Location that the particles are coming from – the engine itself
  • 71. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter • Location that the particles are coming from • Responsible for determining how many particles will be created at any given time – the engine itself
  • 72. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter • Location that the particles are coming from • Responsible for determining how many particles will be created at any given time – the engine itself • Manages the state of the previous two components
  • 73. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter • Location that the particles are coming from • Responsible for determining how many particles will be created at any given time – the engine itself • Manages the state of the previous two components • Responsible for removing dead particles from the system
  • 74. 2D Particle Engine • Anatomy of a Particle Engine – particles • Velocity, Angles – particle emitter • Location that the particles are coming from • Responsible for determining how many particles will be created at any given time – the engine itself • Manages the state of the previous two components • Responsible for removing dead particles from the system.
  • 75. 2D Particle Engine • Particle Public class Particle
  • 76. 2D Particle Engine • Particle • ParticleEngine2D Public class Particle Public class ParticleEngine2D
  • 77. 2D Particle Engine • Particle Public class Particle
  • 78. 2D Particle Engine • Particle • The Particle's Properties Public class Particle
  • 79. 2D Particle Engine Public class Particle public Texture2D Texture { get; set; } public Vector2 Position { get; set; } public Vector2 Velocity { get; set; } public float Angle { get; set; } public float AngularVelocity { get; set; } public Color Color { get; set; } public float Size { get; set; } public int TTL { get; set; } • Particle • The Particle's Properties
  • 80. 2D Particle Engine • Particle • The Particle's Properties Public class Particle public Texture2D Texture { get; set; } public Vector2 Position { get; set; } public Vector2 Velocity { get; set; } public float Angle { get; set; } public float AngularVelocity { get; set; } public Color Color { get; set; } public float Size { get; set; } public int TTL { get; set; }
  • 81. 2D Particle Engine • Particle • The Particle's Properties Public class Particle public Texture2D Texture { get; set; } public Vector2 Position { get; set; } public Vector2 Velocity { get; set; } public float Angle { get; set; } public float AngularVelocity { get; set; } public Color Color { get; set; } public float Size { get; set; } public int TTL { get; set; }
  • 83. 2D Particle Engine • Update() public void Update() { TTL--; Position += Velocity; Angle += AngularVelocity; }
  • 84. 2D Particle Engine • Update() public void Update() { TTL--; Position += Velocity; Angle += AngularVelocity; }
  • 85. 2D Particle Engine • Draw() public void Draw(SpriteBatch spriteBatch) { Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height); Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2); spriteBatch.Draw(Texture, Position, sourceRectangle, Color, Angle, origin, Size, SpriteEffects.None, 0f); }
  • 86. 2D Particle Engine • Particle • ParticleEngine2D Public class Particle Public class ParticleEngine2D
  • 87. 2D Particle Engine Public class ParticleEngine2D
  • 88. 2D Particle Engine Public class ParticleEngine2D • Properties private Random random; public Vector2 EmitterLocation { get; set; } private List<Particle> particles; private List<Texture2D> textures;
  • 89. 2D Particle Engine public void Update() { int total = 10; for (int i = 0; i < total; i++) { particles.Add(GenerateNewParticle()); } for (int particle = 0; particle < particles.Count; particle++) { particles[particle].Update(); if (particles[particle].TTL <= 0) { particles.RemoveAt(particle); particle--; } } }
  • 90. 2D Particle Engine public void Update() { int total = 10; for (int i = 0; i < total; i++) { particles.Add(GenerateNewParticle()); } for (int particle = 0; particle < particles.Count; particle++) { particles[particle].Update(); if (particles[particle].TTL <= 0) { particles.RemoveAt(particle); particle--; } } }
  • 91. 2D Particle Engine public void Draw(SpriteBatch spriteBatch) { spriteBatch.Begin(); for (int index = 0; index < particles.Count; index++) { particles[index].Draw(spriteBatch); } spriteBatch.End(); }
  • 92. 2D Particle Engine public void Draw(SpriteBatch spriteBatch) { spriteBatch.Begin(); for (int index = 0; index < particles.Count; index++) { particles[index].Draw(spriteBatch); } spriteBatch.End(); }
  • 93. 2D Particle Engine • Game1 calling
  • 94. 2D Particle Engine • In Update() • In Draw()
  • 95. 2D Particle Engine • In Update() • In Draw() particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); particleEngine.Update();
  • 96. 2D Particle Engine • In Update() • In Draw() particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); particleEngine.Update(); particleEngine.Draw(spriteBatch);
  • 97. 2D Particle Engine • In Update() • In Draw() particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); particleEngine.Update(); particleEngine.Draw(spriteBatch);
  • 98. 2D Particle Engine • Test it, Very nice! • Can easily be ported to windows phone! – Visit my mobile crash course on slideshare / Windows Phone slide: http://www.slideshare.net/ZGTRZGTR/mobile-software-engineering-crash-course-c06-windowsphone/ • App-2DParticleEngines • You can test it on Windows Mobile!