Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 18th, 2007, 10:26 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 pong menu problem

I started reading the book and following the coding on my laptop, but on chapter 2, on the part that we are suppost to see the menu for the first time by using the TestMenuSprites() test, I don't see any menu, only the background and the code doesn't give me any erros or warnings. But the book says that I am suppost to be seeing the menu. If I run the code that I download from here, the game works and the menu appears.
Is the book right on that part?
Thanks.
  #2 (permalink)  
Old May 19th, 2007, 06:23 AM
Registered User
 
Join Date: May 2007
Location: , , Denmark.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hard to tell what the problem might be.

Have you implemented the Rendersprite methods?
Have you implemented the renderToSprite class, the Drawsprites() method and are you using that method in the pong game draw() routine?

  #3 (permalink)  
Old May 19th, 2007, 07:27 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by phsarjk
 Hard to tell what the problem might be.

Have you implemented the Rendersprite methods?
Have you implemented the renderToSprite class, the Drawsprites() method and are you using that method in the pong game draw() routine?

Please can you elaborate on this abit more for the more dim (Me) people.

Maybe some source code

  #4 (permalink)  
Old May 19th, 2007, 07:59 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by phsarjk
 Hard to tell what the problem might be.

Have you implemented the Rendersprite methods?
Have you implemented the renderToSprite class, the Drawsprites() method and are you using that method in the pong game draw() routine?

Yes, I did.
Yes, I did.
And yes, the Drawsprites() are called inside the Draw() routine.

I think that the source code should be replaced by parts inside chapters. This way we could compare the code that we are writing against the code that the autor wrote. For example, on chapter 2, if I look at the code, it is different from the code on the book until the part that I am. I don't know if the code will change to become like that later.


  #5 (permalink)  
Old May 19th, 2007, 09:04 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here are the replacements for the incorrect areas:

public static void TestMenuSprites()
        {
            StartTest(
                delegate
                {
                    testGame.RenderSprite(testGame.menuTexture,
                        new Rectangle(512-XnaPongLogoRect.Width/2, 150,
                        XnaPongLogoRect.Width, XnaPongLogoRect.Height),
                        XnaPongLogoRect);
                    testGame.RenderSprite(testGame.menuTexture,
                        new Rectangle(512-MenuSingleplayerRect.Width/2, 300,
                        MenuSingleplayerRect.Width, MenuSingleplayerRect.Height),
                        MenuSingleplayerRect);
                    testGame.RenderSprite(testGame.menuTexture,
                        new Rectangle(512-MenuMultiplayerRect.Width/2, 350,
                        MenuMultiplayerRect.Width, MenuMultiplayerRect.Height),
                        MenuMultiplayerRect, Color.Orange);
                    testGame.RenderSprite(testGame.menuTexture,
                        new Rectangle(512-MenuExitRect.Width/2, 400,
                        MenuExitRect.Width, MenuExitRect.Height),
                        MenuExitRect);
                });
        } // TestMenuSprites()




        public void RenderSprite(Texture2D texture, Rectangle rect, Rectangle? sourceRect,
            Color color)
        {
            sprites.Add(new SpriteToRender(texture, rect, sourceRect, color));
        } // RenderSprite(texture, rect, sourceRect, color)

        public void RenderSprite(Texture2D texture, Rectangle rect, Rectangle? sourceRect)
        {
            RenderSprite(texture, rect, sourceRect, Color.White);
        } // RenderSprite(texture, rect, sourceRect)

        public void RenderSprite(Texture2D texture, int x, int y, Rectangle? sourceRect,
            Color color)
        {
            RenderSprite(texture,
                new Rectangle(x, y, sourceRect.Value.Width, sourceRect.Value.Height),
                sourceRect, color);
        } // RenderSprite(texture, rect, sourceRect)

        public void RenderSprite(Texture2D texture, int x, int y, Rectangle? sourceRect)
        {
            RenderSprite(texture,
                new Rectangle(x, y, sourceRect.Value.Width, sourceRect.Value.Height),
                sourceRect, Color.White);
        } // RenderSprite(texture, rect, sourceRect)

        public void RenderSprite(Texture2D texture, Rectangle rect, Color color)
        {
            RenderSprite(texture, rect, null, color);
        } // RenderSprite(texture, rect, color)

        public void RenderSprite(Texture2D texture, Rectangle rect)
        {
            RenderSprite(texture, rect, null, Color.White);
        } // RenderSprite(texture, rect)

        public void RenderSprite(Texture2D texture)
        {
            RenderSprite(texture, new Rectangle(0, 0, 1024, 768), null, Color.White);
        } // RenderSprite(texture)

  #6 (permalink)  
Old May 19th, 2007, 12:00 PM
Registered User
 
Join Date: May 2007
Location: , , Denmark.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmmm...

If you have implemented all the methods you should be able to see the menu.
At least, if you are running the test, instead of the main game.

like so:
Code:
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    {
        //comment out main game for testing of menu

        //using (PongGame game = new PongGame())
        //{
        //    game.Run();
        //}

        PongGame.TestMenuSprites();
    } 
}
  #7 (permalink)  
Old May 24th, 2007, 09:51 PM
Wrox Author
 
Join Date: May 2007
Location: Hannover, , Germany.
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to abi.exdream.com
Default

If you have a problem like this try to zip up your project and post it here so we can take a look at it and figure out why nothing is on the screen.

Setting breakpoints at the place you expect the rendering to happen is also useful to make sure the code is executed. Other than that there are often cases in which sprites (or other content) is not rendered at all because the sprites are not flushed on the screen with RenderAllSprites or you could do everything right, but then overpaint the screen or even clear it, which will also result in an empty screen.

http://abi.exdream.com
  #8 (permalink)  
Old May 25th, 2007, 06:40 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Setting a breakpoint would be your best bet. The thing about this book is that it is not a "Step by Step" type of book in that alot of coding is implied. (For example, the book doesn't explicitly tell you to set up all of the RenderSprites methods to reference the RenderSprite method with the signature: text, rect, sourceRect, color)

In any case, in your Program.cs file, set a breakpoint on PongGame.TestMenuSprites() this will allow you to trace the program flow of the game from the very begining. TestMenuSprites will call this overload of RenderSprite:

       public void RenderSprite(Texture2D texture, Rectangle rect, Rectangle? sourceRect)
        {
            RenderSprite(texture, rect, sourceRect, Color.White); //<--This call is important as it adds the texture to the list, without this reference, you list will be empty and DrawSprites() will exit as soon as you call it.
        }
Which, in turn, calls this overload of RenderSprite
        public void RenderSprite(Texture2D texture, Rectangle rect, Rectangle? sourceRect,
            Color color)
        {
            sprites.Add(new SpriteToRender(texture, rect, sourceRect, color));
        }
If I had to guess, I would think that you are not correctly calling the above RenderSprite that adds your texture to the list hence the call to DrawSprite() exits as soon as its entered since your List is empty.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #9 (permalink)  
Old May 25th, 2007, 10:37 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you all. The code from Zulbaric worked. It was the RenderSprites codes.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 04: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
Pong Game Help -XM- BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 4 June 20th, 2007 02:23 PM



All times are GMT -4. The time now is 08:18 PM.


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