p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 (http://p2p.wrox.com/forumdisplay.php?f=325)
-   -   Pong probs --- Help... (http://p2p.wrox.com/showthread.php?t=65085)

ironchef January 7th, 2008 03:34 PM

Pong probs --- Help...
Im really getting aggrivated at this computer... Whenever i go to build my game file, it says SpaceBakground file cannot be located. Ive placed the .dll in the content file, changed the Asset name and gotten the syntax correct. Ive even copied the code straight from the source code. Why isnt it working? here's the code I have(check the source code file for full code since I ended up copying and pasting):

protected override void LoadGraphicsContent(bool loadAllContent){
    if (loadAllContent){
    // Create sprite batch
    spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

    // Load all our content
    backgroundTexture = content.Load<Texture2D>
    menuTexture = content.Load<Texture2D>("PongMenu");
    gameTexture = content.Load<Texture2D>("PongGame");
    audioEngine = new AudioEngine("PongSound.xgs");
    waveBank = new WaveBank(audioEngine, "Wave Bank.xwb");
        if (waveBank != null)
            soundBank = new SoundBank(audioEngine, "Sound
    } // if
} // LoadGraphicsContent(loadAllContent)

IronChef - http://www.freewebs.com/cool_recipes

firefoxmsp January 8th, 2008 03:20 AM

yeah, thank god someone else is having this problem. i have been struggling with this as well. i'm still waiting for someone to answer my post from a couple days ago.

abi.exdream.com January 18th, 2008 05:12 AM

Hi ironchef,

does not look like your source code is wrong, but my guess is that there is no content file named "SpaceBackground" in the root directory (you can verify that by searching for a SpaceBackground.xnb file in the root directory of your output folder (probably \bin\Debug or \bin\x86\Debug).

If you have a content directory and have not redirected the root of the content loading directory (which would be a feature of XNA 2.0) the content manager will search in the application root directory, but not in the \Content directory, where your file might be located.

Alternatively if you have problems with content files you can also load the Textures directly via Texture2D.LoadFromFile(filename), then use a .dds file, which must obviously exist at the filename path too, but it is easier to check if this works than going though the content pipeline.

Hope this helps, if not please zip up your project and attach it here or email it to me (abi@exdream.com) so I can take a look.


firefoxmsp January 19th, 2008 07:36 PM

so i added the SpaceBackground.xnb to the solution explorer. now i get no errors but debugger (ContentLoadException) still points to:

 backgroundTexture = content.Load<Texture2D>("SpaceBackground");


Arkantos666 January 6th, 2009 02:50 AM

in the constructor of the class just include following

Content.RootDirectory = "Content";
i guess the code is prety self explanatory.

tkn_one February 8th, 2009 12:31 PM

Hi all ...

Sorry for not knowing how to starting a new thread ... related to Pong ...

I have error with sourceRect.Width and sourceRect.Height not defined in RenderSprite method (on page 38 of the book). "Width" and "Height" seems not to be passed for each of the menu texture from the testMenuSprites on page 36.

Is there a declare statement somewhere that I have missed?


"Error 1 'System.Nullable<Microsoft.Xna.Framework.Rectangle >' does not contain a definition for 'Width' and no extension method 'Width' accepting a first argument of type 'System.Nullable<Microsoft.Xna.Framework.Rectangle >' could be found (are you missing a using directive or an assembly reference?) C:\Users\Tung\Documents\Visual Studio 2008\Projects\WindowsGame1\WindowsGame1\Game1.cs 187 84 WindowsGame1"

philip_cole February 21st, 2009 04:12 PM

Hi tkn_one,

As the paragraph above the RenderSprite code says, sourceRect is of type Nullable Rectangle, not a normal Rectangle, i.e. it could be null. This measn you cannot call Width directly from it. Instead you have to use the Value property (defined in the Nullable type) to get the actual rectangle if there is one. SO you would say something like:

Aside from that the DrawSprites method in the book is using the Width and Height of the sprite.rect, not the sourceRect, which is simply passed along to the spriteBatch.Draw method. So make sure you aren't getting the two mixed up.
Hope this helps

P.S. to start a new thread, go the main forum page for the book, and press the blue "New Thread" button just above the table of threads.

All times are GMT -4. The time now is 03:16 AM.

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