|
|
Beginner - Intermediate Tutorials
Last post 04-28-2008, 6:24 PM by Sueds. 47 replies.
-
10-12-2007, 1:34 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Beginner - Intermediate Tutorials
Hello, I'm working on a college grant using XNA and teaching to younger students using tutorials which I've written. I've written these in the last 2-3 weeks and are pretty basic but I'm finally getting to some better and more interesting things for any beginner to intermediate XNA programmer (Tutorial 3+ will be more intermediate). (Note: Some C# knowledge is required) Please take a look at the following and let me know what you think (these are constantly being updated when errors are found and I should be back here a few more times with some new tutorials for you all). Full Tutorial List (Updated Nov 30, 2007):
Have a 1.0 refresh XNA project you want converted into 2.0 (Beta)?
Use this article to convert your project easily. XNA Development: Tutorial 1 - Installing Visual Studio C# Express Edition, installing XNA Game Studio Express 2.0 (Beta) and its templates. XNA Development: Tutorial 2 - Creating your first project and understanding what is created in the new project; also a secondary introduction to the development environment. XNA Development: Tutorial 3 - Writing and implementing a GameModel class used to place and render models within your scene. Get the house model files for
this tutorial HERE. XNA Development: Tutorial 4 - Make a very basic GameCamera class that allows you to move through a 3D world utilizing forward and back movement, strafe left, strafe right, and turning left and right (sorry no up and down!). XNA Development: Tutorial 5 - The GameSprite class will bring that much needed flare to your project, adding 2D HUD elements such as a rotating map and health box. Get
the HUD files for this tutorial HERE. XNA Development: Tutorial 6 - Using the GameState class will both clean up your code and provide different game states such as InGame and Pause. XNA Development: Tutorial 7 - The GameAudio class will make your demo sound just as awesome as it looks! Otherwise you can find all the tutorials HERE. Any feedback is welcome, thanks! A bit about me: I am a student pursuing my bachelor's degree in Applied Mathematics and Computer Science. I currently have an associate's degree in Computer Programming. Games have been a part of my life since age 5 when I started playing them and started programming them in late high school where I created my first game (a really choppy RPG) in Visual Basic 6 in my first ever programming class. You can find more on me at my site (or on my resume).
|
|
-
10-16-2007, 10:39 AM |
-
EnragedSteak
-
-
-
Joined on 09-15-2007
-
-
Posts 31
-
-
|
Re: Beginner - Intermediate Tutorials
Well from what I can see they appear to be well structured. I must admit I havent gone through them with a fine toothcomb but from what I did read it was good. They may be basic but they are reasonably clear and easy to follow. One trivial thing I would note is that in document 3 you list a Render() function then move onto explain it. I think it may be easier to follow if you quote each line or couple of lines before talking about them as you tend to keep having to scroll back to the page above to see what it is your discussing. Otherwise, good start and I like the "problems" section at the end (maybe rename this though? Exercises?) - nice to make people think a little more than just typing out lines of code.
My Blog
|
|
-
10-16-2007, 11:11 AM |
-
10-18-2007, 11:54 AM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Thanks for the feedback guys. I've taking into account what you've said and changed tutorial 3 to be easier to read without going back. I also changed the 'Suggested Problems' and have added the second link into tutorial 3. I've just finished coding up a really basic camera class that supports movement and turn (no up down movement yet) and I should be starting to write that one soon.
|
|
-
10-18-2007, 8:18 PM |
-
grnemo
-
-
-
Joined on 10-12-2007
-
Greece, Athens
-
Posts 6
-
-
|
Re: Beginner - Intermediate Tutorials
XNAtticus I have to prepare a presentation about XNA (pure introduction) and right now I am planning the layout. I think, that I will follow your example about nice and clean, step by step introduction to this (and not theories, pros and cons about XNA only). Keep programming. Aggelos
Microsoft Student Partner Personal PageDelicate Sound of DevelopmentStudentGuru.gr Online Community
|
|
-
10-24-2007, 3:16 PM |
-
I 1 SH0T KILL I
-
-
-
Joined on 10-24-2007
-
-
Posts 6
-
-
|
Re: Beginner - Intermediate Tutorials
im trying your tut num3, and the render code gives me errors.
Error 2 The name 'view' does not exist in the current context C:\Documents and Settings\Admin\My Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\GameModel.cs 57 13 WindowsGame1
Error 1 The name 'projection' does not exist in the current context C:\Documents and Settings\Admin\My Documents\Visual Studio 2005\Projects\WindowsGame1\WindowsGame1\GameModel.cs 55 13 WindowsGame1
|
|
-
10-24-2007, 5:46 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Good question! It's my fault, I forgot to have you add two global class variables (something I've addressed differently in Tutorial 4 that's being worked on). Up towards the top where you've got: //Class model storage private Model gModel;
//Aspect Ratio private float aspectRatio = 0.0f;
//Position of our model private Vector3 positionVector; Add the following just below it: private Matrix projection; private Matrix view; Let me know if that fixes it, I'll make sure to append this to the tutorial tonight and get that updated version up later tonight. That sounds awesome grnemo! If you find anyone interested with XNA make sure to suggest this site and forums (and even my tutorials if you want!).
|
|
-
10-26-2007, 8:29 AM |
-
I 1 SH0T KILL I
-
-
-
Joined on 10-24-2007
-
-
Posts 6
-
-
|
Re: Beginner - Intermediate Tutorials
Ah, yeh thank you. it works :P but how would i change where the 3d model is stored, as i want mine in "Content\Model\ModelName"
would it be
myHouse = new GameModel(content, graphics, "Content\\Models\\ModelNameHere");
Maybe?
|
|
-
10-26-2007, 11:53 AM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
That's exactly it. It's easy if you just add the folders inside your project in the Solution Explorer and move your model right in there within your project. BUT! Make sure all the texture images and such are also placed in that folder otherwise you'll receive a wierd compiler error saying it can't find whatever the texture file is named (XNA links models and that during build instead of while it's running).
In the tutorials I have posted I really only use one type of file, the model files. I've finished tutorial 4 and will post it when it's edited and ready. But, Tutorial 5 will introduce a new type of file (sprites) and I'll start off with placing all my content in folder structures like you've asked about. Good question and you'll see a more official version when tutorial 5 is up.
|
|
-
11-05-2007, 11:23 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Boy, it sure has been quiet around here lately. Let's liven things up a bit: XNA Development: Tutorial 4Tutorial 4 focuses on the GameCamera class, a basic forward, back, left strafe, right strafe, left turn, right turn, camera class. Also included is a small primer on linear algebra (used in the camera class). UPDATE: I've changed the post so I'll post all the tutorials I have done in the first post as I finish them so I don't have to keep double-triple posting. Notice, Tutorial 4 and Tutorial 5 have been added.
|
|
-
01-14-2008, 2:12 AM |
-
Aphelion
-
-
-
Joined on 01-11-2008
-
Arrakis, Dune, Desert Planet
-
Posts 32
-
-
|
Re: Beginner - Intermediate Tutorials
Great tutorials! I've learned more from these than any other resource so far. I'm at the end of Tut #4 and I'm getting an error:
"No overload for method 'Render' takes '0' arguments"
and references: "myHouse.Render();" in game1.cs.
I'm not sure how to resolve this error. Any help would be GREAT!
Thanks again for sharing these wonderful tutorials, they're a real life saver!
The Spice Must Flow.
|
|
-
01-14-2008, 10:57 AM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
That line should read: myHouse.Render(camera.GetViewMatrix(), camera.GetProjectionMatrix()); Check out page 11 of Tut 4 for that line. I hope this helps, keep me posted on if you get that fixed or not. Quick update, I've been on winter break from school for the last month approximately and haven't worked on the Tutorials since but don't worry, I head back to school next week and should be able to get more tutorials out. (Maybe I mentioned this but I've got 5 more tutorials planned in this series). I'm working on a game for my portfolio currently but what I've done in it really helps me write these tutorials since I can see if they're practical to use in a game scenario. I'll take the next week to work on the game and get back to the tutorials next week.
|
|
-
01-14-2008, 11:15 AM |
-
Aphelion
-
-
-
Joined on 01-11-2008
-
Arrakis, Dune, Desert Planet
-
Posts 32
-
-
|
Re: Beginner - Intermediate Tutorials
Thank you! Got it to work just fine. Not really sure how I missed that but all is well now. Thank you for your help.
I'm really looking forward to the next batch of tutorials! Like I mentioned, these have been a great help in getting me started. I love the way you explain things in laymans terms, it helps me associate. Thanks for your help and for writting these tutorials.
The Spice Must Flow.
|
|
-
01-15-2008, 1:47 PM |
-
What The Geek
-
-
-
Joined on 01-06-2008
-
-
Posts 3
-
-
|
Re: Beginner - Intermediate Tutorials
Hey, great tutorial - very useful.
I've got one little problem though - I'm quite certain that I've just done something stupid here, but the prolem I'm having is with tutorial 3. In fact, I'm almost certain I can pin it on the placement of this line of code -
GameModel myHouse;
The problem I'm having is that upon hitting F5 I get no debug errors - problem is, I get no house either.Any suggestions would be greatly appreciated.
|
|
-
01-15-2008, 2:09 PM |
-
Jim Perry
-
-
-
Joined on 03-05-2007
-
Abingdon, MD
-
Posts 1,086
-
-
|
Re: Beginner - Intermediate Tutorials
Did you do the other lines as well:
myHouse = new GameModel(this.Content, graphics, "houseModel");
myHouse.SetPosition(0.0f, 0.0f, 5.0f);
myHouse.Render();
Jim Perry Here's what I'm up to.
|
|
-
01-15-2008, 2:15 PM |
-
What The Geek
-
-
-
Joined on 01-06-2008
-
-
Posts 3
-
-
|
Re: Beginner - Intermediate Tutorials
yup.
I'm sorting back through everything now looking for any no brainer mistakes, and I'm coming up empty.
Thanks for the reply btw.
|
|
-
01-15-2008, 2:26 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Make sure you add the house files to your project like this:
1) In Visual Studio right click on the Content folder and select Add > Existing Item. Browse to wherever you've saved the house file (the .X file in the .ZIP) and the textures. Make sure to add all three files (the two textures and the model).
If this doesn't help me let me know what the error you're receiving is.
|
|
-
01-15-2008, 2:32 PM |
-
What The Geek
-
-
-
Joined on 01-06-2008
-
-
Posts 3
-
-
|
Re: Beginner - Intermediate Tutorials
Definitely already added them - I don't want to take up your time, I'll keep poking around with it and see if i can't get it working.
Thanks for the help though.
|
|
-
01-15-2008, 2:35 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Nah don't worry about it I like helping people on bugs in these tutorials. Plus I'm at work and bored out of my mind. Is the project working just without a house? If you want, send me your files (matt@insidegamer.org).
EDIT: Make sure your mesh Render method is similar to the one in the tutorial (a short viewstrum will not show it) or make sure you have all the numbers correct as far as setting the first vector to (0, 0, 0).
|
|
-
01-16-2008, 5:51 PM |
-
Blackgate
-
-
-
Joined on 01-13-2008
-
-
Posts 3
-
-
|
Re: Beginner - Intermediate Tutorials
I'm definitely loving these tutorials. I've only got a casual experience with coding (where talking NWN Aurora and Flash ActionScript here) as I'm more artist than programmer, so I needed this. Keep up the great work.
I got stuck in tutorial #5.
At the end where it is time implement the GameSprite Class you indicate to add a line under the LoadContent() method in the Game1.cs file. I'm assuming that is referring to the part that reads:
protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { }
I'm not sure where to put the line:
gameSprites = new GameSprite(this.Content, spritBatch);
Does it go above or inside the if statement?
I put it inside, but the only error I got was concerning the spriteBatch.
The error reads, "The name 'spriteBatch does not exist in current context." I moved the line above the if statement, but I get the same error. I combed through the tut, but I couldn't see where you defined this. Did I miss it in a previous tut?
It would be awesome if you included the working project file with your tuts so we can peek at the source code if we run into things like this.
Thanks again
|
|
-
01-16-2008, 6:57 PM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Blackgate:I'm definitely loving these tutorials. I've only got a casual experience with coding (where talking NWN Aurora and Flash ActionScript here) as I'm more artist than programmer, so I needed this. Keep up the great work.
I got stuck in tutorial #5.
At the end where it is time implement the GameSprite Class you indicate to add a line under the LoadContent() method in the Game1.cs file. I'm assuming that is referring to the part that reads:
protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { }
I'm not sure where to put the line:
gameSprites = new GameSprite(this.Content, spritBatch);
Does it go above or inside the if statement?
I put it inside, but the only error I got was concerning the spriteBatch.
The error reads, "The name 'spriteBatch does not exist in current context." I moved the line above the if statement, but I get the same error. I combed through the tut, but I couldn't see where you defined this. Did I miss it in a previous tut?
It would be awesome if you included the working project file with your tuts so we can peek at the source code if we run into things like this.
Few items here to address. If you are using XNA Game Studio 2.0 (which you probably should be but if not, don't worry), you won't have the lines: if (loadAllContent) { }
Instead (and this is very imortant), you will have this line: spriteBatch = new SpriteBatch(GraphicsDevice);
In the first case, you should be able to put the gameSprite initialization within the if(loadAllContent) brackets. If you're using 2.0 just make sure you place it after spriteBatch = ..... (That spriteBatch is what you are passing to your GameSprite constructor). Since I've changed the tutorials to support 2.0, I don't need to declare a new SpriteBatch object (it's already done in a default game). This line: gameSprites = new GameSprite(this.Content, spritBatch);
Looks like you are missing an 'e' on the word 'spriteBatch'. Maybe that's giving you the error? Again, if you are using 1.0 you need to define a SpriteBatch object. In 2.0, the object is already built for you (another advantage of getting 2.0). But, if you are using 1.0, make sure you add the following to the top of your Game1 class around your other objects: Then in the LoadContent (in the braces) you will need to create one. Since I have 2.0 I'm not positive I remember if the constructor is the same, but it will probably look like: spriteBatch = new SpriteBatch(graphics); So, I would first try fixing that spelling error if it is wrong. If it isn't fixed either 1) create and instantiate a new SpriteBatch object (XNA 1.0), or 2) Place the line after the spriteBatch initialization in LoadContent() (XNA 2.0). Hope this isn't confusing, I'm trying to cover both 1.0 and 2.0 because it sounds like you have 1.0. If this doesn't fix it come back and let me know which version of XNA you're running and the error (you can send me the code if you like, matt at insidegamer.org) I'll try to get the code up with the tutorials. I had struggled with doing that only because 1) for some it could encourage copy and paste and no learning will really take place, and 2) my code may be inconsistant with yours. But since you've asked for it I'll try to get it up there ASAP (within a few weeks). Let me know if all this helps and thanks for the kind words on my tuts! :)
|
|
-
01-17-2008, 8:31 AM |
-
Blackgate
-
-
-
Joined on 01-13-2008
-
-
Posts 3
-
-
|
Re: Beginner - Intermediate Tutorials
Thanks for the quick response.
I defined the SpriteBatch object and that got rid of my error. I thought I was working in 2.0, but perhaps I started working on the tut before I downloaded the update.
I'm getting another problem now when it comes to loading my sprite.
The error states:
ContentLoadException was unhandled Error loading "Sprites\crdSamp". file not found
This is firing on the line of code in the GameSprite.cs that reads:
newSprite.spriteTex = gameContent.Load<Texture2D>("Sprites\\" + spriteName);
Now, I get what it is saying, I'm just not sure what I did wrong importing my crdsamp.png into the project.
I right clicked on the Content folder and created a new folder naming it "Sprites". Here I right clicked on the Sprites folder, picked Add > Existing Item and chose the "crdSamp.png". I looked in the Sprites folder and the .png is definitely in there, so I'm not sure what could be going wrong. Unless there is something special that was in the previous tuts that absolutely had to be there for this to fire, but I didn't think the 3D stuff would affect 2D sprites. I'm trying to make a 2D card game that uses prerendered 3D graphics, so I'm more interested in bringing in 2D... I correctly guessed that I could leave out the line that keeps the 2D content oriented with the camera, so I thought I was on a role. Heh.
I hope I included enough information for you to spot what I may have done wrong. I think I may just redo the tut to make sure I have a 2.0 version anyway...
Thanks again
|
|
-
01-17-2008, 10:36 AM |
-
XNAtticus
-
-
-
Joined on 10-12-2007
-
WI, USA
-
Posts 51
-
-
|
Re: Beginner - Intermediate Tutorials
Could you list your lines that import that Sprite? For example, gameSprites.AddSprite("crdSamp", "crdSamp"....) Traditionally an error like that means you specified the path of the sprite wrong somewhere in code and XNA looks in the wrong spot, doesn't find anything, then errors. Also, the Sol | | |
|