SlideShare a Scribd company logo
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2011, 2012, 2013, 2014
XNA Game Development
L06 – Input, Audio and Video Playback
Input
Keyboard, Mouse, Touch, Joystick, Sensors, etc.
Keyboard Input
Keyboard Input
• Why static?
KeyboardState state = Keyboard.GetState();
Keyboard Input
• Using Keyboard states
KeyboardState state = Keyboard.GetState();
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input
• Using Keyboard states
bool leftArrowKeyDown = state.IsKeyDown(Keys.Left);
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input
• Using Keyboard states
KeyboardState state = Keyboard.GetState();
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input
• Using Keyboard states
KeyboardState state = Keyboard.GetState();
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input - Checking for Key Presses
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input - Checking for Key Presses
if(state.IsKeyDown(Keys.Left))
{
// do something here
}
Keyboard Input - Checking for Key Presses
Keys[] pressedKeys = state.GetPressedKeys();
Keyboard Input - Key Modifiers
if(
(
state.IsKeyDown(Keys.LeftControl)|| state.IsKeyDown(Keys.RightControl)
)
&& state.IsKeyDown(Keys.C)
)
{
// Do something here when Ctrl-C is pressed
}
Mouse Input
Mouse Input - Showing the Mouse
this.IsMouseVisible = true;
Mouse Input - Mouse Input?
MouseState mouseState = Mouse.GetState();
if(mouseState.LeftButton == ButtonState.Pressed)
{
// Do whatever you want here
}
Mouse Input - Mouse Input?
• Mouse built-in methods
– LeftMouseButton
– MiddleMouseButton
– RightMouseButton
– XButton1
– XButton2
– X
– Y
– ScrollWheelValue
Mouse Input - Location
• Getting Location
int x = mouseState.X;
int y = mouseState.Y;
Mouse.SetPosition(xLocation, yLocation);
• Setting Location
Xbox(Or Other!) Controller Input
Controller Input
Controller Input
• GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
if(gamePadState.IsConnected)
{
// then it is connected, and we can do stuff here
}
if(gamePadState.Buttons.X == ButtonState.Pressed)
{
// do something
}
Controller Input
float maxSpeed = 0.1f;
float changeInAngle = gamePadState.Thumbsticks.Left.X * maxSpeed;
// this variable is defined elsewhere
angle += changeInAngle;
Controller Input – Vibration effect!
Controller Input – Vibration Cool effect!
GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
Audio
Audio
• Audio in XNA
• Audio Suggestions for Games
• A Simple Way to Play Sound Effects in XNA
• A Simple Way to Play Background Music in XNA
• Using XACT
• Using XACT Projects in an XNA Game
• XACT Sound Loops
• 3D Audio Effects: Location
• 3D Audio Effects: Attenuation based on Distance
Audio in XNA
• The Concept
Audio Suggestions For Games
• Audio Suggestions For Games
– royalty free music in google.com
– http://www.incompetech.com/m/c/royalty-free/
– http://www.flashkit.com/
• Use sound in your game. It adds a lot to the game. Don't just ignore it. ( Not in
our uni :( )
Playing Sound Effects
• Adding Sound Effects to your Game
– Managing Content!
Playing Sound Effects
• WAV Audio File (.wav extension)
private SoundEffect effect;
effect = Content.Load<SoundEffect>("SoundFX/ExtraLife");
Playing Sound Effects
• WAV Audio File (.wav extension)
private SoundEffect effect;
effect = Content.Load<SoundEffect>("SoundFX/ExtraLife");
effect.Play();
float volume = 1.0f;
effect.Play(volume);
float volume = 1.0f;
float pitch = -1.0f;
float pan = -1.0f;
bool loop = true;
effect.Play(volume, pitch, pan, loop);
Playing Sound Effects
• SoundEffectInstances class
SoundEffectInstance effectInstance = effect1.Play();
effectInstance.Stop();
Playing Sound Effects
• SoundEffectInstances class
SoundEffectInstance effectInstance = effect1.Play();
effectInstance.Stop();
Playing Background Music
• Using the Song and MediaPlayer Classes to Play Audio
Song song = Content.Load<Song>("song_title");
// Put the name of your song here instead of "song_title"
MediaPlayer.Play(song);
MediaPlayer.IsRepeating = true;
Using XACT
• Cross-platform Audio Creation Tool
• The concept
• Using XACT
– Using XACT
– Using XACT Projects in an XNA Game
– XACT Sound Loops
– 3D Audio Effects: Location
– 3D Audio Effects: Attenuation based on Distance
Using XACT
• Small Tutorials
– http://rbwhitaker.wikidot.com/audio-tutorials
• http://rbwhitaker.wikidot.com/using-xact
• http://rbwhitaker.wikidot.com/playing-sound
• http://rbwhitaker.wikidot.com/xact-sound-loops
• http://rbwhitaker.wikidot.com/3d-audio-effects-location
– Books
• Microsoft Book
• Aaron Reed (O’Reilly)
Video Playback
Video Playback
• Loading the Video in XNA, Game1 Global Scope
Video video;
VideoPlayer player;
Video Playback
• Loading the Video in XNA, Game1 Global Scope
• LoadContent()
Video video;
VideoPlayer player;
video = Content.Load<Video>("AVideoToPlayback");
player = new VideoPlayer();
Video Playback
• Starting the Video
player.Play(video);
Video Playback
• Starting the Video
• Update()
player.Play(video);
if (player.State == MediaState.Stopped)
{
player.IsLooped = true;
player.Play(video);
}
Video Playback
• Looping
player.IsLooped = true;
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoTexture = player.GetTexture();
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoTexture = player.GetTexture();
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoTexture = player.GetTexture();
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoTexture = player.GetTexture();
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoTexture = player.GetTexture();
if (videoTexture!= null)
{
spriteBatch.Begin();
spriteBatch.Draw(videoTexture, new Rectangle(0, 0, 400, 300), Color.White);
spriteBatch.End();
}

More Related Content

PDF
Game Audio Making (sound effects) by Satriyo
PDF
The Next-Gen Dynamic Sound System of Killzone Shadow Fall
PDF
Deep dive into Android’s audio latency problem
PPT
Core audio
PPTX
DSP Anime export to Unity and other middleware
KEY
Foot Pedals
PPT
Lua and adaptive audio - Don Veca (Activision)
PPTX
Technology used
Game Audio Making (sound effects) by Satriyo
The Next-Gen Dynamic Sound System of Killzone Shadow Fall
Deep dive into Android’s audio latency problem
Core audio
DSP Anime export to Unity and other middleware
Foot Pedals
Lua and adaptive audio - Don Veca (Activision)
Technology used

What's hot (18)

PDF
Core Audio in iOS 6 (CocoaConf DC, March 2013)
PPTX
Audio Mixer in Unity5 - Andy Touch
PDF
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
PPTX
Xbox 360
DOC
Xbox one
KEY
Sharing
PDF
Gamelog
PPTX
GoldWave
PDF
Squidiverse Production Pipeline
PDF
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
PPTX
Building your own arcade cabinet
PDF
Core MIDI and Friends
PPTX
A Brief Guide to Game Engines
PPT
See'n'Sound LE 2.0 promo
PPTX
Audio equalizer
TXT
Readme i'm en pilotes
PDF
Absolutist: Porting to major platforms within a minute
PPTX
Week Two - Game Platforms (Additional Material)
Core Audio in iOS 6 (CocoaConf DC, March 2013)
Audio Mixer in Unity5 - Andy Touch
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Xbox 360
Xbox one
Sharing
Gamelog
GoldWave
Squidiverse Production Pipeline
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Building your own arcade cabinet
Core MIDI and Friends
A Brief Guide to Game Engines
See'n'Sound LE 2.0 promo
Audio equalizer
Readme i'm en pilotes
Absolutist: Porting to major platforms within a minute
Week Two - Game Platforms (Additional Material)
Ad

Viewers also liked (7)

PDF
XNA L11–Shaders Part 2
PDF
XNA L01–Introduction
PDF
XNA L08–Amazing XNA Utilities
PDF
XNA L04–Primitives, IndexBuffer and VertexBuffer
PPTX
Ogdc 2013 2d artist the first steps
PDF
XNA L10–Shaders Part 1
PDF
XNA L07–Skybox and Terrain
XNA L11–Shaders Part 2
XNA L01–Introduction
XNA L08–Amazing XNA Utilities
XNA L04–Primitives, IndexBuffer and VertexBuffer
Ogdc 2013 2d artist the first steps
XNA L10–Shaders Part 1
XNA L07–Skybox and Terrain
Ad

Similar to XNA L06–Input, Audio and Video Playback (20)

PDF
Web Audio Made Easy with Howler.js
PPTX
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
PPTX
Modern Improvisation World
PPTX
Windows phone 7 xna
PPTX
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
PDF
PDF
Introduction to Game programming with PyGame Part 1
PPT
Prasentation Managed DirectX
PPTX
XNA and Windows Phone
PPS
God Of War : post mortem
PPT
Game Audio Post-Production
PPT
Game programming with Groovy
PPT
Wakka Monkey - Game Development
PDF
The Online Tech of Titanfall
PDF
Confrontation Audio GDC 2009
PPTX
Supersize your production pipe enjmin 2013 v1.1 hd
PPTX
Beginning android games
PPTX
Kinect for Windows Quickstart Series
PDF
Drumwavy VST VST3 Audio Unit: Orchestral and Ethnic Percussion VST, VST3 and ...
Web Audio Made Easy with Howler.js
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
Modern Improvisation World
Windows phone 7 xna
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
Introduction to Game programming with PyGame Part 1
Prasentation Managed DirectX
XNA and Windows Phone
God Of War : post mortem
Game Audio Post-Production
Game programming with Groovy
Wakka Monkey - Game Development
The Online Tech of Titanfall
Confrontation Audio GDC 2009
Supersize your production pipe enjmin 2013 v1.1 hd
Beginning android games
Kinect for Windows Quickstart Series
Drumwavy VST VST3 Audio Unit: Orchestral and Ethnic Percussion VST, VST3 and ...

More from Mohammad Shaker (20)

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

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Spectroscopy.pptx food analysis technology
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
sap open course for s4hana steps from ECC to s4
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Spectroscopy.pptx food analysis technology
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

XNA L06–Input, Audio and Video Playback

  • 1. Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L06 – Input, Audio and Video Playback
  • 2. Input Keyboard, Mouse, Touch, Joystick, Sensors, etc.
  • 4. Keyboard Input • Why static? KeyboardState state = Keyboard.GetState();
  • 5. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 6. Keyboard Input • Using Keyboard states bool leftArrowKeyDown = state.IsKeyDown(Keys.Left); if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 7. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 8. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 9. Keyboard Input - Checking for Key Presses if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 10. Keyboard Input - Checking for Key Presses if(state.IsKeyDown(Keys.Left)) { // do something here }
  • 11. Keyboard Input - Checking for Key Presses Keys[] pressedKeys = state.GetPressedKeys();
  • 12. Keyboard Input - Key Modifiers if( ( state.IsKeyDown(Keys.LeftControl)|| state.IsKeyDown(Keys.RightControl) ) && state.IsKeyDown(Keys.C) ) { // Do something here when Ctrl-C is pressed }
  • 14. Mouse Input - Showing the Mouse this.IsMouseVisible = true;
  • 15. Mouse Input - Mouse Input? MouseState mouseState = Mouse.GetState(); if(mouseState.LeftButton == ButtonState.Pressed) { // Do whatever you want here }
  • 16. Mouse Input - Mouse Input? • Mouse built-in methods – LeftMouseButton – MiddleMouseButton – RightMouseButton – XButton1 – XButton2 – X – Y – ScrollWheelValue
  • 17. Mouse Input - Location • Getting Location int x = mouseState.X; int y = mouseState.Y; Mouse.SetPosition(xLocation, yLocation); • Setting Location
  • 20. Controller Input • GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); if(gamePadState.IsConnected) { // then it is connected, and we can do stuff here } if(gamePadState.Buttons.X == ButtonState.Pressed) { // do something }
  • 21. Controller Input float maxSpeed = 0.1f; float changeInAngle = gamePadState.Thumbsticks.Left.X * maxSpeed; // this variable is defined elsewhere angle += changeInAngle;
  • 22. Controller Input – Vibration effect!
  • 23. Controller Input – Vibration Cool effect! GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
  • 24. Audio
  • 25. Audio • Audio in XNA • Audio Suggestions for Games • A Simple Way to Play Sound Effects in XNA • A Simple Way to Play Background Music in XNA • Using XACT • Using XACT Projects in an XNA Game • XACT Sound Loops • 3D Audio Effects: Location • 3D Audio Effects: Attenuation based on Distance
  • 26. Audio in XNA • The Concept
  • 27. Audio Suggestions For Games • Audio Suggestions For Games – royalty free music in google.com – http://www.incompetech.com/m/c/royalty-free/ – http://www.flashkit.com/ • Use sound in your game. It adds a lot to the game. Don't just ignore it. ( Not in our uni :( )
  • 28. Playing Sound Effects • Adding Sound Effects to your Game – Managing Content!
  • 29. Playing Sound Effects • WAV Audio File (.wav extension) private SoundEffect effect; effect = Content.Load<SoundEffect>("SoundFX/ExtraLife");
  • 30. Playing Sound Effects • WAV Audio File (.wav extension) private SoundEffect effect; effect = Content.Load<SoundEffect>("SoundFX/ExtraLife"); effect.Play(); float volume = 1.0f; effect.Play(volume); float volume = 1.0f; float pitch = -1.0f; float pan = -1.0f; bool loop = true; effect.Play(volume, pitch, pan, loop);
  • 31. Playing Sound Effects • SoundEffectInstances class SoundEffectInstance effectInstance = effect1.Play(); effectInstance.Stop();
  • 32. Playing Sound Effects • SoundEffectInstances class SoundEffectInstance effectInstance = effect1.Play(); effectInstance.Stop();
  • 33. Playing Background Music • Using the Song and MediaPlayer Classes to Play Audio Song song = Content.Load<Song>("song_title"); // Put the name of your song here instead of "song_title" MediaPlayer.Play(song); MediaPlayer.IsRepeating = true;
  • 34. Using XACT • Cross-platform Audio Creation Tool • The concept • Using XACT – Using XACT – Using XACT Projects in an XNA Game – XACT Sound Loops – 3D Audio Effects: Location – 3D Audio Effects: Attenuation based on Distance
  • 35. Using XACT • Small Tutorials – http://rbwhitaker.wikidot.com/audio-tutorials • http://rbwhitaker.wikidot.com/using-xact • http://rbwhitaker.wikidot.com/playing-sound • http://rbwhitaker.wikidot.com/xact-sound-loops • http://rbwhitaker.wikidot.com/3d-audio-effects-location – Books • Microsoft Book • Aaron Reed (O’Reilly)
  • 37. Video Playback • Loading the Video in XNA, Game1 Global Scope Video video; VideoPlayer player;
  • 38. Video Playback • Loading the Video in XNA, Game1 Global Scope • LoadContent() Video video; VideoPlayer player; video = Content.Load<Video>("AVideoToPlayback"); player = new VideoPlayer();
  • 39. Video Playback • Starting the Video player.Play(video);
  • 40. Video Playback • Starting the Video • Update() player.Play(video); if (player.State == MediaState.Stopped) { player.IsLooped = true; player.Play(video); }
  • 42. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  • 43. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  • 44. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  • 45. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  • 46. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture(); if (videoTexture!= null) { spriteBatch.Begin(); spriteBatch.Draw(videoTexture, new Rectangle(0, 0, 400, 300), Color.White); spriteBatch.End(); }