George Clingerman

      XNADevelopment.com
posts - 188, comments - 1508, trackbacks - 181

My Links

News



Twitter












Tag Cloud

Article Categories

Archives

Post Categories

. XNADevelopment.com .

XNADevelopment.com - The Wizard: Part One (2.0)

thewizard First, I just want to say thanks for all the great feedback I've gotten in comments and email. I don't make any money from doing these tutorials, I don't want donations and I'm not a fan of ads so your comments are what keep me going. Silly I know, but just a little "Thanks!" really does make all the work that goes into the site and these tutorials worth it. So "Thanks!" for the comments and emails. Keep them coming! I love hearing back from people using the tutorials and benefiting from them.

I have been working on completely re-doing the Wizard tutorial and the re-write is now down and posted. I have broken this tutorial into four parts to make it a bit more digestible and easier to follow. This is Part 1 and it covers getting basic input from the player via the keyboard and then using that input to move a sprite around on the screen.

You can head on over and check out, The Wizard: Part 1- Moving a Sprite around the Screen.

As always, the source code is provided along with the tutorial and feedback is strongly encouraged and welcome. Enjoy!

Technorati Tags:
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Saturday, March 15, 2008 9:37 AM | Filed Under [ XNA Development XNA ]

Feedback

Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Awesome, helped lots!
3/20/2008 9:52 PM | Cameron
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Great didatic, great tutorial.Just simple and useful.
thanks (:
5/5/2008 5:47 AM | Caio
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Great introduction to inheritance.
Thanks very much for all your hard work! Wish I could buy you a beer.
5/23/2008 10:03 PM | Mycenae
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I really like your tutorials a lot. I have been looking a lot of places for XNA game development for beginners and your site actually caught my time the longest.

I will definitely continue reading on your other projects. Right now I am looking for tutorials to deal with mouse event handlers. Hope to find something similar on your next tutorials. Thanks
7/28/2008 3:30 PM | MiMi
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thank you for all the tutorials. i am beginner and you have helped me understand how things work. I still need to learn a lot, but this is the best place i have found on the net to get started.

Thank You

Attila
8/12/2008 9:16 PM | Attila
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thank you. I've been a programmer for years but just started tinkering around with game developemnt. These tutorials are the perfect starting place. Your sprites collection is very good too.
8/31/2008 8:01 AM | Frank
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thanks a lot for this great tutorial! I was just wondering if you could actualy explain the best way to flip the sprite so it follows the orientation. :) That would be even more awesome! Once again, thank you!
9/16/2008 4:42 PM | Guillaume
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I just completed this tutorial with my own sprites and I gotta say I'm loving it. Your tutorials are all so clear and well explained. keep up the good work.

I look forward to seeing more tutorials soon :)
10/13/2008 11:11 AM | Andrew
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thank you. I just finished moving my Wizard.
you're so cool !!
10/31/2008 8:19 PM | Yuna
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Excelent tutorial for people that is new to XNA.
11/6/2008 4:55 PM | Ricardo
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

IT is really a great tutorial, easier than the one I found in MS official website.

However I want to ask something that when i complie project on XNADevelopment.com - The Wizard: Part One (2.0)
after making sprite class changes I got an error in project that mSpriteTexture is null (for scale property), and that is rightly so as my Game1.cs init function is trying to set Scale property before LoadContent gets called where we set that variable. so I guess you need to initialize mSpriteTexture before that.
11/11/2008 11:48 PM | Sumit Guta
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I had the same problem with the compilation error saying mSpriteTexture is null. To make the code compile correctly I omitted it and just put Scale instead of the multiplication of width and the multiplication of height in the specified regions and finished the coding. I didn't find any errors so now I don't even know the importance of this section of coding. Any explanations are greatly appreciated and I greatly appreciate your tutorials and how you stay true to object orientated mentality. Coding is much simpler and cleaner when following that approach.
12/19/2008 11:51 PM | Jeffrey Schmidt
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Excellent tutorials, very clearly explained and based on good design principles, good stuff, thank you
1/1/2009 4:38 PM | Jim
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I also had the same problem. But putting scale there only will not serve it's purpose. I just placed an if condition to check that if the texture has been loaded, then apply the size to the sprite.


public float Scale

{

get { return mScale;}

set

{

mScale = value;

//Recalculate the Size of the Sprite with the new scale
Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));

}

}


TO


public float Scale
{
get { return mScale; }
set
{
mScale = value;

// If mSpriteTexture is set, then
if (mSpriteTexture != null)
//Recalculate the Size of the Sprite with the new scale
Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));
}
}

1/17/2009 6:51 PM | Syed
Gravatar

# Help

hello,

i am having some trouble going slightly freestyle. Meaning that i am trying to create a project that combine the first bunch of tutorials making a wizard move, jump, duck and shoot fire on a scrolling background.

How would i do that???

thanks

Gilad
9/2/2009 8:02 PM | gilad
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

hi,
this tutorial was very helpful.
i learnt a lot from this.

i have small doubt.

suppose i have a character (may be a man's image) instead of the sprite(square image). the character will have legs.
i have images which depict the leg movement.
say the images are like this(i store them in a collection)
stand still
move left leg
move right leg
so for every update i set the texture2d as the next image to be shown.
next image can be got by (collection[ (counter +1)%3]
counter starts with 0.
now the problem arises.
the user presses right once, so the left leg is moved and then the character has his left leg forward, the character has also moved a little to the right. but once the character is moved it should come back to its stand still position)
this never happens.
how do i achieve this?

thanks in advance!!
1/3/2010 9:45 PM | nandan
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thanks for the tutorial, however, I tried copying this onto the Windows Phone 7 SDK and for some reason, my wizard won't move! Has anyone else had any trouble with this? When I push the arrow keys, nothing happens. Does anyone have any suggestions?
7/11/2010 11:54 PM | geitben
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

great tutorials but when i add the drawing code for the Spriteclass:

new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height),
Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);

an error sais: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

do i write it all on the same line? and i tried a couple of things and i tried putting ( before Color.white and then it sais: Method name expected

i really need help, im new and your tutorials are great but this is really bugging me
8/23/2010 4:27 AM | lime
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Well, you're missing the first part of that. The actual line of code looks like this:

theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);

And you don't have to write it all on the same line. For C#, commands aren't complete until a semi-colon ; is encountered. This allows you to break up your code for readability.

If you're new to starting out, I highly recommend though that you take some time to learn C# first without throwing in the complications of XNA and game development on top of that. You don't have to become an expert, but understanding the language and the basic C# syntax will make your progress go much faster and smoothly.
8/23/2010 9:39 AM | George Clingerman
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

<h1>Dez Bryant Jersey</h1>
Saints Jerseys
8/23/2010 10:28 PM | Dallas cowboys shop
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

oh, ok thanks very much, I am getting a book on C# in about a week to learn a bit more.
thanks alot.
8/24/2010 5:24 AM | lime
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Hi,
I actually have the same issue someone above has mentioned about the Draw section. Even being a little familiar with C#, I still am not understanding what the error, "Object reference not set to an instance of an object" means when trying to compile. I tried adding new somewhere in there but it wasn't working. Just wondering if I need to add anything or take something out for it to work and so I can move on to your other tutorials?
1/10/2011 8:00 PM | CJ
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I'm getting the same issue as Syed, Jeffrey Schmidt and Sumit Guta - an error stating "NullReferenceException was unhandled - Object reference not set to an instance of an object." for the line

Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale));

The issue is with mSpriteTexture but I'm not sure what I need to be doing to fix it.
2/9/2011 1:46 PM | Jackal
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

i spent quit a lot of time to study this movement, and i can`t understand how those classes update each other and how they update the Game.cs. How can u call a draw method from the sprite class if in the Game.cs u initialized the wizzard class???
2/22/2011 2:17 PM | married
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

It is not the first time I visit your site. Every time I read your posts and admire how perfectly you write. Every single article is very well structured and organized accordingly to SEO needs that search engines like. I am also trying to follow your example, but it is still very tough for me as I have not got much expertise in it! Thanks for sharing it..
4/9/2011 6:25 AM | cell phone spyware
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Considerably, the read is totally the freshest on this valuable topic. I fit in with your conclusions and will continuously look forward to your upcoming updates. Just saying thanks will not just be sufficient, for the fantastic usefulness in your writing. I will right away grab your rss feed to stay privy of any updates.......
5/4/2011 2:08 AM | cell phone spyware
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Hi! Thanks so much for sharing your wealth of information. I just started in this and I'm getting to know it better! Many thanks for all of your hard work!
5/13/2011 10:45 PM | Mobile Spy
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

the best way to flip the sprite so it follows the orientation. :) That would be even more awesome! Once again, thank you! I was just wondering if you could actualy explain
6/1/2011 5:02 AM | medical coding and billing
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

I was just wondering if you could actualy explain Once again, thank you! the best way to flip the sprite so it follows the orientation. :) That would be even more awesome!
6/1/2011 5:02 AM | medical coding and billing
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Superbe article, vraiment simple et utile. Bravo pour sa mise en ligne. C’est ce genre d’information que le public (et moi en particulier) recherche.
Home Automation || <a href="http://www.myseasonalsensations.com/"rel="follow">Gourmet Gift Baskets
7/5/2011 5:48 AM | nitesh
Gravatar

# rak03

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
7/5/2011 5:49 AM | Home Automation
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Interesting articles are published here. By reading it I acquired great deal of knowledge on various subject. Very good comments to read and recommend others. Thank you for sharing with us....

clubmz reviews
7/20/2011 2:21 AM | halree anjino
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

This article gives the light in which we can observe the reality.
This is very nice one and gives indepth information. Thanks for this nice article.car search
7/21/2011 1:52 AM | car search
Gravatar

# ranger

This is Part 1 and it covers getting basic input from the player via the keyboard and then using that input to move a sprite around on the screen.
9/12/2011 12:48 AM | medical biller
Gravatar

# RANGER

This is Part 1 and it covers getting basic input from the player via the keyboard and then using that input to move a sprite around on the screen.http://digitalnewscafe.net/finding-a-career-in-medical-billing-and-coding-is-easy/
9/14/2011 4:53 AM | medicoding
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Great tutorial, but I think when you say "overrides are the same method but with different or extra parameters," you mean overload. Override is when a subclass overrides a superclass's method.
9/27/2011 1:15 PM | Phillip Schmidt
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thank you for all the tutorials. i am beginner and you have helped me understand how things work.
10/4/2011 2:45 AM | Mail Forwarding London
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

Thanks for the tutorial, however, I tried copying this onto the Windows Phone 7 SDK and for some reason, my wizard won't move! Has anyone else had any trouble with this? When I push the arrow keys, nothing happens. Does anyone have any suggestions?
7/11/2010 11:54
11/20/2011 10:24 AM | poster mockup
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

. As of yet I have not seen much of a return on my time investment. As I am new at this I assume that I am doing something wrong, any suggestions.”
11/21/2011 3:39 AM | Digital Marketing Orlando
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

congratulations and good luck with future lot of tutorials. I hope to come out very successful and have many fans through their
11/25/2011 12:51 AM | Clasament Turcia
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

they are able to feel free to buy needed things. Moreover, a lot of banks present auto loan for different persons.
12/19/2011 12:55 AM | commit
Gravatar

# re: XNADevelopment.com - The Wizard: Part One (2.0)

hey, why after running the program, the line
mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName);

gives an exception ContentLoadException: Error loading "WizardSquare". File not found.

o.O I tried to startover, but still, I got that... why? :(
12/26/2011 12:00 AM | apple
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: