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 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 Display Modes
  #1 (permalink)  
Old March 6th, 2008, 11:13 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems already!

Hi,

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!

Thanks,

Kenny.:(
  #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
Default

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:

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

// Render all sprites
foreach (SpriteToRender sprite in sprites)
{
    spriteBatch.Draw(sprite.texture,
        // 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),
        sprite.sourceRect,
        sprite.color);
}

spriteBatch.End();
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:
Code:
testGame.RenderSprite(testGame.menuTexture, 
    512 - XnaPongLogoRect.Width / 2, 150, 
    XnaPongLogoRect);
But the downloadable code says this:
Code:
testGame.RenderSprite(testGame.menuTexture,
    new Rectangle(512-XnaPongLogoRect.Width/2, 150,
    XnaPongLogoRect.Width, XnaPongLogoRect.Height),
    XnaPongLogoRect);
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.".

Edit:
Ugh, so apparently the downloadable code for this book available here isn't even for XNA 2.0:
http://www.wrox.com/WileyCDA/WroxTit...load_code.html

You have to go to the author's personal website to get the correct code:
http://exdream.no-ip.info/blog/2008/...acingGame.aspx

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
Default

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!

Kenny.
:)

  #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
Default

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>
    RenderSprite(texture,
        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
Default

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

 


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
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 03:23 AM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 01:34 PM
Problems kilika Javascript 1 October 3rd, 2003 02:42 AM



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


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