Your SlideShare is downloading. ×
0
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2011, 2012, 2013, 2014
XNA Game Development
L06 – Input, Audio and Video Pl...
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 s...
Keyboard Input
• Using Keyboard states
bool leftArrowKeyDown = state.IsKeyDown(Keys.Left);
if(state.IsKeyDown(Keys.Left))
...
Keyboard Input
• Using Keyboard states
KeyboardState state = Keyboard.GetState();
if(state.IsKeyDown(Keys.Left))
{
// do s...
Keyboard Input
• Using Keyboard states
KeyboardState state = Keyboard.GetState();
if(state.IsKeyDown(Keys.Left))
{
// do s...
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.IsK...
Mouse Input
Mouse Input - Showing the Mouse
this.IsMouseVisible = true;
Mouse Input - Mouse Input?
MouseState mouseState = Mouse.GetState();
if(mouseState.LeftButton == ButtonState.Pressed)
{
//...
Mouse Input - Mouse Input?
• Mouse built-in methods
– LeftMouseButton
– MiddleMouseButton
– RightMouseButton
– XButton1
– ...
Mouse Input - Location
• Getting Location
int x = mouseState.X;
int y = mouseState.Y;
Mouse.SetPosition(xLocation, yLocati...
Xbox(Or Other!) Controller Input
Controller Input
Controller Input
• GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
if(gamePadState.IsConnected)
{
// then i...
Controller Input
float maxSpeed = 0.1f;
float changeInAngle = gamePadState.Thumbsticks.Left.X * maxSpeed;
// this variable...
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 Back...
Audio in XNA
• The Concept
Audio Suggestions For Games
• Audio Suggestions For Games
– royalty free music in google.com
– http://www.incompetech.com/...
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>("So...
Playing Sound Effects
• WAV Audio File (.wav extension)
private SoundEffect effect;
effect = Content.Load<SoundEffect>("So...
Playing Sound Effects
• SoundEffectInstances class
SoundEffectInstance effectInstance = effect1.Play();
effectInstance.Sto...
Playing Sound Effects
• SoundEffectInstances class
SoundEffectInstance effectInstance = effect1.Play();
effectInstance.Sto...
Playing Background Music
• Using the Song and MediaPlayer Classes to Play Audio
Song song = Content.Load<Song>("song_title...
Using XACT
• Cross-platform Audio Creation Tool
• The concept
• Using XACT
– Using XACT
– Using XACT Projects in an XNA Ga...
Using XACT
• Small Tutorials
– http://rbwhitaker.wikidot.com/audio-tutorials
• http://rbwhitaker.wikidot.com/using-xact
• ...
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 = Con...
Video Playback
• Starting the Video
player.Play(video);
Video Playback
• Starting the Video
• Update()
player.Play(video);
if (player.State == MediaState.Stopped)
{
player.IsLoop...
Video Playback
• Looping
player.IsLooped = true;
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoText...
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoText...
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoText...
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoText...
Video Playback
• Drawing the Video, Draw()
Texture2D videoTexture = null;
if (player.State!= MediaState.Stopped)
videoText...
Upcoming SlideShare
Loading in...5
×

XNA L06–Input, Audio and Video Playback

295

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
295
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
38
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "XNA L06–Input, Audio and Video Playback"

  1. 1. Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L06 – Input, Audio and Video Playback
  2. 2. Input Keyboard, Mouse, Touch, Joystick, Sensors, etc.
  3. 3. Keyboard Input
  4. 4. Keyboard Input • Why static? KeyboardState state = Keyboard.GetState();
  5. 5. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  6. 6. Keyboard Input • Using Keyboard states bool leftArrowKeyDown = state.IsKeyDown(Keys.Left); if(state.IsKeyDown(Keys.Left)) { // do something here }
  7. 7. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  8. 8. Keyboard Input • Using Keyboard states KeyboardState state = Keyboard.GetState(); if(state.IsKeyDown(Keys.Left)) { // do something here }
  9. 9. Keyboard Input - Checking for Key Presses if(state.IsKeyDown(Keys.Left)) { // do something here }
  10. 10. Keyboard Input - Checking for Key Presses if(state.IsKeyDown(Keys.Left)) { // do something here }
  11. 11. Keyboard Input - Checking for Key Presses Keys[] pressedKeys = state.GetPressedKeys();
  12. 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 }
  13. 13. Mouse Input
  14. 14. Mouse Input - Showing the Mouse this.IsMouseVisible = true;
  15. 15. Mouse Input - Mouse Input? MouseState mouseState = Mouse.GetState(); if(mouseState.LeftButton == ButtonState.Pressed) { // Do whatever you want here }
  16. 16. Mouse Input - Mouse Input? • Mouse built-in methods – LeftMouseButton – MiddleMouseButton – RightMouseButton – XButton1 – XButton2 – X – Y – ScrollWheelValue
  17. 17. Mouse Input - Location • Getting Location int x = mouseState.X; int y = mouseState.Y; Mouse.SetPosition(xLocation, yLocation); • Setting Location
  18. 18. Xbox(Or Other!) Controller Input
  19. 19. Controller Input
  20. 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. 21. Controller Input float maxSpeed = 0.1f; float changeInAngle = gamePadState.Thumbsticks.Left.X * maxSpeed; // this variable is defined elsewhere angle += changeInAngle;
  22. 22. Controller Input – Vibration effect!
  23. 23. Controller Input – Vibration Cool effect! GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
  24. 24. Audio
  25. 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. 26. Audio in XNA • The Concept
  27. 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. 28. Playing Sound Effects • Adding Sound Effects to your Game – Managing Content!
  29. 29. Playing Sound Effects • WAV Audio File (.wav extension) private SoundEffect effect; effect = Content.Load<SoundEffect>("SoundFX/ExtraLife");
  30. 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. 31. Playing Sound Effects • SoundEffectInstances class SoundEffectInstance effectInstance = effect1.Play(); effectInstance.Stop();
  32. 32. Playing Sound Effects • SoundEffectInstances class SoundEffectInstance effectInstance = effect1.Play(); effectInstance.Stop();
  33. 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. 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. 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)
  36. 36. Video Playback
  37. 37. Video Playback • Loading the Video in XNA, Game1 Global Scope Video video; VideoPlayer player;
  38. 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. 39. Video Playback • Starting the Video player.Play(video);
  40. 40. Video Playback • Starting the Video • Update() player.Play(video); if (player.State == MediaState.Stopped) { player.IsLooped = true; player.Play(video); }
  41. 41. Video Playback • Looping player.IsLooped = true;
  42. 42. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  43. 43. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  44. 44. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  45. 45. Video Playback • Drawing the Video, Draw() Texture2D videoTexture = null; if (player.State!= MediaState.Stopped) videoTexture = player.GetTexture();
  46. 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(); }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×