| ubergods's profilePat's spaceBlogGuestbookNetwork | Help |
Pat's space |
|||||
|
|
December 02 Adding an MP3 Soundtrack To Your XNA GameVersion 3.0 of the XNA framework makes it very easy to import and use MP3 files in their native format within our games. Earlier versions of the framework required us to convert these files and use XACT to play music. Below I'll show you how easy it is to add an MP3 soundtrack to your own game.
The first step is to add the MP3 file to your project's shared content directory which I will assume anyone at this stage in XNA development knows how to do. Next we must invoke the XNA Media library in your class which is done by using the following include statement at the top of the .cs file:
using Microsoft.Xna.Framework.Media; Next we will need to declare a variable which will represent an instance of our MP3 within the class and then load the content (the MP3) into that variable. I do this within the LoadContent function of my primary game class. I have included an example statement below:
Song backgroundSong;backgroundSong = Content.Load<Song>("Sounds/background"); Now that we have an object representing our MP3 in our class, all we need to do is tell the MediaPlayer which is included with XNA.Framework.Media, to play the MP3. If you want your MP3 to loop, you simply specify this as well. I have included examples of these statements below: MediaPlayer .IsRepeating = true;MediaPlayer.Play(backgroundSong); We also have the option of pausing the MP3 at its current position and then resuming again where it left off: MediaPlayer .Pause();MediaPlayer.Resume(); Stopping the MP3 is also a simple function call:
MediaPlayer .Stop();Below is an example from my PunkBoy game which allows me to pause and resume the background song based off the user pressing the 'S' key. public class PunkBoyGame : Microsoft.Xna.Framework.Game{ ... bool playMusic = true; KeyboardState previousState = Keyboard.GetState(); ... { KeyboardState keyboardState = Keyboard.GetState(); ... if (keyboardState.IsKeyDown(Keys.S) && !previousState.IsKeyDown(Keys.S)) { if (playMusic) { playMusic = false; MediaPlayer.Pause(); } else if (!playMusic) { playMusic = true; MediaPlayer.Resume(); } } ... previousState = Keyboard.GetState(); base.Update(gameTime); } November 30 PunkBoy Official ReleasePunkboy has officially been released. Feel free to download the source and/or the game at http://www.codeplex.com/punkboy
The game was written in C# using Microsoft's XNA Game Studio 3.0, and based off of the Platformer starter kit included with XNA. Much of the starter kit's code remains in place but has been updated, modified and tweaked into its current state. Following is a list of some of the changes:
Professor Samuel Stokes' Blog October 23 XNA RPG Starter Kit Quest ModificationAt the bottom of this post I have added a short video that shows how simple it is to modify the XNA RPG Starter Kit and add your own quests and items. The creators club site has a very basic and helpful tutorial here which will walk you through adding your own quest to the game. The modification and/or addition of a new item to the game follows the same principles. Below is an example of the XML file for my Sword of 1000 Truths, I will highlight the key points that I changed in Green. <?xml version="1.0" encoding="utf-8" ?> <XnaContent> <Asset Type="RolePlayingGameData.Weapon"> <Name>Sword of 1000 Truths</Name> The name that appears in the item description window <Description>The Sword of 1000 Truths is a legendary sword that will easily strike down the most powerful of enemies</Description> The item description that appears when viewing the sword in game. <GoldValue>100000</GoldValue> The value of the sword if you were to sell it, this sword is worth a LOT of money. <IsDroppable>true</IsDroppable> <MinimumCharacterLevel>1</MinimumCharacterLevel> I allow the player to equip this sword at level 1 <SupportedClasses> <Item>Warrior</Item> <Item>Paladin</Item> </SupportedClasses> <IconTextureName>Sword07a</IconTextureName> <TargetDamageRange> <Minimum>1000</Minimum> Minimum damage is 1000HP as opposed to 4HP that the short sword would cause <Maximum>2000</Maximum> Maximum damage is 2000HP as opposed to the 8HP that the short sword would cause </TargetDamageRange> <SwingCueName>SwordSwing</SwingCueName> <HitCueName>SwordHit</HitCueName> <BlockCueName>SwordBlock</BlockCueName> <Overlay> <TextureName>Spells\OverlayMelee</TextureName> <FrameDimensions>111 130</FrameDimensions> <FramesPerRow>1</FramesPerRow> <Animations> <Item> <StartingFrame>1</StartingFrame> <EndingFrame>1</EndingFrame> <Interval>200</Interval> <IsLoop>false</IsLoop> </Item><a href="http://video.msn.com/video.aspx?vid=9b9f08ea-719d-486f-8912-024e87f07fe1" target="_new" title="XNA RPG Starter Kit Quest Modification">Video: XNA RPG Starter Kit Quest Modification</a> </Animations> </Overlay> </Asset> </XnaContent> Thanks, Professor Samuel Stokes' Blog ubergods, your source for uber...period XNA RPG Starter Kit Quest ModificationHigher Quality Downloadable WMV Version of this Video September 23 Pong With ClassesThis is an update on an earlier blog I posted regarding creating a simple pong game using XNA...
My professor Samuel Stokes asked us to take our pong game created in XNA and move a large portion of the code to a separate class. A bit tedious and frustrating at first, but I realized it was just a matter of keeping some of the sprite declarations in the main program and passing them as variables to the methods within the class I had built. I used one class for all of the methods and variables I moved out so I could declare most of the variables within the class instead of passing them along each time. You can check out the code on my SkyDrive through the link at the bottom of this entry.
- Pat
September 11 Game IdeaSo way back in 2001 when flash was first becoming popular, I wrote a short little cartoon called "Punkboy vs. Poserboy."
I'm thinking about expanding on this idea for a game using XNA, perhaps it will be titled "Punkboy: Rise of the Scene Kid Army." The goal of the game will be to save the world from the putrid movement of self-absorbed so called "scene kids." Perhaps Punkboy will advance through the levels, getting new weapons (doc martins, studded belt, gutterstench, etc) and defeating increasingly pompous Scenesters until the final battle where he must destroy the birthplace and sanctuary of many of these types - MySpace.
Just an idea...
- Pat
|
||||
|
|