Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6
This is the forum to discuss the Wrox book Professional XNA Game Programming: For Xbox 360 and Windows by Benjamin Nitschke; ISBN: 9780470126776
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 18th, 2007, 01:16 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pong Game Help

Alright I'm having a bit of a problem on the pong game... I think this might be a silly error on my part, but I thought I'd check here to see if anyone else has had this problem:

I have coded the pong game all the way up to the top of page 38,I am supposed to see the space background drawn on my screen but I get an error that says:

 
Quote:
quote:Error - The type or namespace name 'PongGame' could not be found (are you missing a using directive or an assembly reference?


Code:
delegate void TestDelegate();
          class TestPongGame : [u]PongGame</u>  
        {
            TestDelegate testLoop;
            public TestPongGame(TestDelegate setTestLoop)
            {
                testLoop = setTestLoop;
            } //TestPongGame(setTestLoop)

            protected override void Draw(GameTime gameTime)
            {
                base.Draw(gameTime);
                testLoop();
            } //Draw (gametime)

        } //Class Ponggame.


I have checked and I'm pretty sure the code is the same as the code I have downloaded. I still think this is something simple. If you would like me to post all the code I have entered I can do so. Thanks!

Reply With Quote
  #2 (permalink)  
Old June 18th, 2007, 06:13 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It might be the namimg convention of one of your .cs files. I think by default, you should have a file called Game1.cs(which includes your Update, Draw, Initialize methods, etc...). If so, rename it to PongGame.cs and see if that works. Or, you can just replace PongGame with Game1 on that line with the error.
Reply With Quote
  #3 (permalink)  
Old June 20th, 2007, 07:14 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much for replying. I changed it to PongGame.cs. But now I'm having another problem, my whole Draw method is now messed up...

Quote:
quote:Error 1 An object reference is required for the nonstatic field, method, or property

Error 2 An object reference is required for the nonstatic field, method, or property

Error 3 An object reference is required for the nonstatic field, method, or property '
Code:
        protected override void Draw(GameTime gameTime)
        {

            [u]SpriteBatch.Begin();</u>
            [u]SpriteBatch.Draw</u>(backgroundTexture,
                new Rectangle(0, 0, width, height),
                Color.LightGray);
            [u]SpriteBatch.End(); </u>

        }


Once again,I have triple checked my code and I can't find anything....Sorry for these nooby questions here,I'm rather new to all this... )
Reply With Quote
  #4 (permalink)  
Old June 20th, 2007, 11:17 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It looks like you haven't created an object of type SpriteBatch yet. You are trying to call class SpriteBatch's methods using the class itself, but you cant. You have to create an object of type SpriteBatch to access the Begin(), Draw(), and End() methods. A class like a blueprint of what an object is supposed to do/contain.

To create an object from the SpriteBatch class:

SpriteBatch anyVariableName = new SpriteBatch(graphics.GraphicsDevice);

anyVariableName(the newly created object) is now an object of type SpriteBatch. Now the object can access SpriteBatch's(the class) methods.

anyVariableName.Begin()
anyVariablevariableName.Draw(), etc...

You might want to look at a simple XNA program to understand its structure, and its 4 major methods(Initialize, LoadGraphicsContent, Update, and Draw).
Reply With Quote
  #5 (permalink)  
Old June 20th, 2007, 02:23 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

EDIT: Problem solved.... I forgot to change the PongBackground's settings. I had it set as a sprite when it should of been a texture...

It all works and I'm ready to move on!

Thanks for the help llonden. Much appreciated. :)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pong probs --- Help... ironchef BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 6 February 21st, 2009 03:12 PM
Pong... cshmny BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 0 October 1st, 2008 09:47 PM
Error Pong? bxrtuff24 BOOK: Professional XNA Programming 2nd Edition ISBN: 978-0-470-26128-6 0 September 28th, 2008 10:33 AM
Xbox 360 Game (2.0) - Pong darktatami BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 1 January 18th, 2008 04:26 AM
Chapter 2 pong menu problem alexmbr BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 8 May 25th, 2007 10:37 PM



All times are GMT -4. The time now is 06:02 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.