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 Programming 2nd Edition ISBN: 978-0-470-26128-6
This is the forum to discuss the Wrox book Professional XNA Programming : Building Games for Xbox 360 and Windows with XNA Game Studio 2.0, 2nd Edition by Benjamin Nitschke; ISBN: 9780470261286
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XNA Programming 2nd Edition ISBN: 978-0-470-26128-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 March 6th, 2008, 12:13 PM
Registered User
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems already!


Is anyone else having problems getting the Pong example to work? I'm trying to get the menu displayed like the one in Fig 2-5 on page 41. I get a CornflowerBlue screen and then it crashses on line...

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStaticMode.None);

stating that "Begin cannot be called again until end is called". I am calling spriteBatch.End() right after the loop as shown in the book! I have double checked my code and can't see anything wrong with it.

It seems like bits of the code are missing from the text (width and height weren't defined, so I've guessed what they should be and created variables for these (as per another thread I found on this site that dealt with the first edition of this book)). Also, should there be code in the two RenderSprite methods on page 38??? I'm finding this all pretty frustrating!


  #2 (permalink)  
Old March 9th, 2008, 04:09 AM
Registered User
Join Date: Apr 2007
Location: Toronto, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Are you sure you don't have spriteBatch.Begin inside of the foreach by mistake?

This is what that excerpt of DrawSprites looks like on my side:

// Start rendering the sprites
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);

// Render all sprites
foreach (SpriteToRender sprite in sprites)
        // Scale to fit resolution
        new Rectangle(
        sprite.rect.X * width / 1024,
        sprite.rect.Y * height / 768,
        sprite.rect.Width * width / 1024,
        sprite.rect.Height * height / 768),

I too encountered the width/height thing, so I went and looked at the downloadable source code for the chapter 2 to see how they were set. (It later turned out that width and height are mentioned on page 58 in the Troubleshooting section.)

Another problem I just came across is that in the TestMenuSprites() listing on page 37, the testGame.RenderSprite(...) bits don't match up with the RenderSprite definition on page 40.

For example, page 37 says this:
    512 - XnaPongLogoRect.Width / 2, 150, 
But the downloadable code says this:
    new Rectangle(512-XnaPongLogoRect.Width/2, 150,
    XnaPongLogoRect.Width, XnaPongLogoRect.Height),
I'm not sure if we're meant to have figured that out on our own or what, but it contradicts the statement on page 41 that "... if you press F5 now, you can see the screen shown in Figure 2-5.".

Ugh, so apparently the downloadable code for this book available here isn't even for XNA 2.0:

You have to go to the author's personal website to get the correct code:

This edition of XNA Programming seems to be a bit sloppy.
  #3 (permalink)  
Old March 10th, 2008, 10:41 AM
Registered User
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for replying.

I've checked and I definitely have the "spriteBatch.Begin" code outside the loop. I'll have to look through the code on the Author's website (thanks for the link).

I agree, it does seem a little sloppy. Another annoyance that I had to work around is on page 39 where it suggests changing the "Main" method. I did this and, of course, it didn't work. I ended-up removing my "StartGame" method and having all the code in "Main" and simply commented-out the relevant parts.

Seems like this book will be a challenge to get through!


  #4 (permalink)  
Old April 7th, 2008, 01:08 AM
Registered User
Join Date: Apr 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I was having exactly that problem, walking through the code line by line (both my code and the source) led me to find another RenderSprite method which had not been inserted. It should be;

public void RenderSprite(Texture2D texture, int x, int y, Rectangle? sourceRect)
    /// <summary>
    /// Render sprite
    /// </summary>
    /// <param name="texture">Texture</param>
    /// <param name="rect">Rectangle</param>
    /// <param name="color">Color</param>
        new Rectangle(x, y, sourceRect.Value.Width, sourceRect.Value.Height),
        sourceRect, Color.White);
} // RenderSprite(texture, x, y)

It worked on my machine.

  #5 (permalink)  
Old April 7th, 2008, 03:36 AM
Registered User
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for letting me know. I'll try and see what happens...


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
Have 2 problems so far... Soulcatcher BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 June 20th, 2007 12:57 PM
2 problems here with me naveed77 Beginning VB 6 1 October 17th, 2006 06:04 PM
c problems saurabh1983in C++ Programming 6 November 29th, 2005 04:23 AM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
Problems kilika Javascript 1 October 3rd, 2003 02:42 AM

All times are GMT -4. The time now is 09:41 PM.

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