Geeks With Blogs
George Clingerman       XNADevelopment.com

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:
Posted on Saturday, March 15, 2008 9:37 AM XNA Development , XNA | Back to top


Comments on this post: XNADevelopment.com - The Wizard: Part One (2.0)

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Awesome, helped lots!
Left by Cameron on Mar 20, 2008 9:52 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Great didatic, great tutorial.Just simple and useful.
thanks (:
Left by Caio on May 05, 2008 5:47 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Great introduction to inheritance.
Thanks very much for all your hard work! Wish I could buy you a beer.
Left by Mycenae on May 23, 2008 10:03 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by MiMi on Jul 28, 2008 3:30 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by Attila on Aug 12, 2008 9:16 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by Frank on Aug 31, 2008 8:01 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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!
Left by Guillaume on Sep 16, 2008 4:42 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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 :)
Left by Andrew on Oct 13, 2008 11:11 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Thank you. I just finished moving my Wizard.
you're so cool !!
Left by Yuna on Oct 31, 2008 8:19 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Excelent tutorial for people that is new to XNA.
Left by Ricardo on Nov 06, 2008 4:55 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by Sumit Guta on Nov 11, 2008 11:48 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by Jeffrey Schmidt on Dec 19, 2008 11:51 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Excellent tutorials, very clearly explained and based on good design principles, good stuff, thank you
Left by Jim on Jan 01, 2009 4:38 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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));
}
}

Left by Syed on Jan 17, 2009 6:51 PM

# Help
Requesting Gravatar...
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
Left by gilad on Sep 02, 2009 8:02 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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!!
Left by nandan on Jan 03, 2010 9:45 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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?
Left by geitben on Jul 11, 2010 11:54 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by lime on Aug 23, 2010 4:27 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by George Clingerman on Aug 23, 2010 9:39 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Left by Dallas cowboys shop on Aug 23, 2010 10:28 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
oh, ok thanks very much, I am getting a book on C# in about a week to learn a bit more.
thanks alot.
Left by lime on Aug 24, 2010 5:24 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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?
Left by CJ on Jan 10, 2011 8:00 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by Jackal on Feb 09, 2011 1:46 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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???
Left by married on Feb 22, 2011 2:17 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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..
Left by cell phone spyware on Apr 09, 2011 6:25 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.......
Left by cell phone spyware on May 04, 2011 2:08 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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!
Left by Mobile Spy on May 13, 2011 10:45 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by medical coding and billing on Jun 01, 2011 5:02 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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!
Left by medical coding and billing on Jun 01, 2011 5:02 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by nitesh on Jul 05, 2011 5:48 AM

# rak03
Requesting Gravatar...
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.
Left by Home Automation on Jul 05, 2011 5:49 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by halree anjino on Jul 20, 2011 2:21 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by car search on Jul 21, 2011 1:52 AM

# ranger
Requesting Gravatar...
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.
Left by medical biller on Sep 12, 2011 12:48 AM

# RANGER
Requesting Gravatar...
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/
Left by medicoding on Sep 14, 2011 4:53 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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.
Left by Phillip Schmidt on Sep 27, 2011 1:15 PM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Thank you for all the tutorials. i am beginner and you have helped me understand how things work.
Left by Mail Forwarding London on Oct 04, 2011 2:45 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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
Left by poster mockup on Nov 20, 2011 10:24 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
. 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.”
Left by Digital Marketing Orlando on Nov 21, 2011 3:39 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
congratulations and good luck with future lot of tutorials. I hope to come out very successful and have many fans through their
Left by Clasament Turcia on Nov 25, 2011 12:51 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
they are able to feel free to buy needed things. Moreover, a lot of banks present auto loan for different persons.
Left by commit on Dec 19, 2011 12:55 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
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? :(
Left by apple on Dec 26, 2011 12:00 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Thank you for all the tutorials. i am beginner and you have helped me understand how things work.
Left by how much does it cost to build a on Feb 13, 2012 1:16 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Donning one thing that complements evening bolero jackets your figure is one of
Left by factdress on May 04, 2012 3:20 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
Very interesting and useful discussion for me. I think this is a common problem for all parents so don't worry about it. Thanks guys for such a great comments, have a good luck.
Left by asos on Jul 05, 2012 12:58 AM

# re: XNADevelopment.com - The Wizard: Part One (2.0)
Requesting Gravatar...
This blog is very useful information for me and guidance.
definition essay ideas
Left by denas on Dec 20, 2012 12:53 AM

Your comment:
 (will show your gravatar)


Copyright © George Clingerman | Powered by: GeeksWithBlogs.net