Search | Statistics | User Listing Forums
XNA Resources
XNA Resources ->  General Discussion -> General Discussion -> View Thread

You are logged in as a guest. ( logon | register )

XNA 4.0 Game Development by Example - Troubleshooting Thread
Jump to page : 1 2
Now viewing page 1 [25 messages per page]
View previous thread :: View next thread
   General Discussion -> General DiscussionMessage format
 
rlsl88
Posted 2010-12-13 9:44 PM (#186)
Subject: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(76.169.200.213)
First off, I love the book! The idea of "less theory, more results" is exactly what I needed in an XNA book after wasting so much time with the now deceased Torque engines.

Second, I did not see a thread specific to troubleshooting this book. As good as this book is, it is inevitable that some readers will stumble. Rather than getting stuck and giving up I thought we could work it out here.

Third, I'm on the third chapter and I'm already stuck! haha I'll post the details next.
Top of the page Bottom of the page
rlsl88
Posted 2010-12-13 9:53 PM (#187 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(76.169.200.213)
My first big stumble:

Page 78 - Steps 4 & 5.

I'm not sure exactly where this code is supposed to go so maybe that is my only problem.

For step 4 I placed the code just outside the 'foreach' in the CheckScoringChain() method. I got the following two errors:

Error 2 Argument 2: cannot convert from 'Microsoft.Xna.Framework.Color' to 'Microsoft.Xna.Framework.Graphics.ColorWriteChannels' C:\...\visual studio 2010\Projects\FloodControl\FloodControl\FloodControl\Game1.cs 255 33 FloodControl
Error 1 The best overloaded method match for 'FloodControl.ScoreZoom.ScoreZoom(string, Microsoft.Xna.Framework.Graphics.ColorWriteChannels)' has some invalid arguments C:\...\visual studio 2010\Projects\FloodControl\FloodControl\FloodControl\Game1.cs 253 48 FloodControl

For step 5 I placed the code block at the end of the Draw() method just before the SpriteBatch.DrawString() call. I got the following three errors:
Error 2 Argument 4: cannot convert from 'Microsoft.Xna.Framework.Graphics.ColorWriteChannels' to 'Microsoft.Xna.Framework.Color' C:\...\visual studio 2010\Projects\FloodControl\FloodControl\FloodControl\Game1.cs 213 21 FloodControl
Error 3 Argument 7: cannot convert from 'float' to 'Microsoft.Xna.Framework.Vector2' C:\...\visual studio 2010\Projects\FloodControl\FloodControl\FloodControl\Game1.cs 216 21 FloodControl
Error 1 The best overloaded method match for 'Microsoft.Xna.Framework.Graphics.SpriteBatch.DrawString(Microsoft.Xna.Framework.Graphics.SpriteFont, string, Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Color, float, Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Graphics.SpriteEffects, float)' has some invalid arguments C:\...\visual studio 2010\Projects\FloodControl\FloodControl\FloodControl\Game1.cs 210 21 FloodControl


I'm going to give it a rest for the moment but please post if you have any ideas. Thanks!




Attachments
----------------
Attachments Game1.cs (13KB - 1 downloads)
Top of the page Bottom of the page
Kurt Jaegers
Posted 2010-12-14 2:54 AM (#188 - in reply to #187)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(108.16.193.145)
All of these errors seem to reference the ScoreZoom class. Can you post what you have for ScoreZoom?
Top of the page Bottom of the page
rlsl88
Posted 2010-12-14 8:50 PM (#189 - in reply to #188)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(76.169.200.213)
Thanks for the help. ScoreZoom.cs is attached.



Attachments
----------------
Attachments ScoreZoom.cs (1KB - 1 downloads)
Top of the page Bottom of the page
rlsl88
Posted 2010-12-15 11:04 PM (#193 - in reply to #189)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(76.169.200.213)
Figured it out!

All of my Color variables defaulted to ColorWriteChannels variables. In ScoreZoom.cs DrawColor and fontColor were both ColorWriteChannels variables.

This was because of Step 2 on page 76. Not only does 'using Microsoft.Xna.Framework.Graphics;' need to be added but also 'using Microsoft.Xna.Framework'.

All is good now.
Top of the page Bottom of the page
ForgedPixels
Posted 2011-01-04 9:17 PM (#203 - in reply to #186)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 2


(68.149.170.235)
Hi, figured I'd piggyback on this troubleshooting thread for the book.

I've been trying out the Lost In Space game, and after setting up the player ship updating and drawing (page 126 I think?), it mentions a couple issues with player movement; that the player can move faster than normal diagonally, and/or with a gamepad moving simultaneously with arrow keys. To fix, it's mentioned to simply normalize the player velocity vector.
I see in the code that the normalization call is already in place in the code in the book, but the normalization isn't actually occuring; diagonal movement and arrowkeys+gamepad can still end up doubling the player movement speed.

My guess was that calling playerSprite.Velocity.Normalize(); wasn't actually assigned the new value to the instance's property, so I tried a way to force it:
playerSprite.NormalizeMe(); //call this instead, where NormalizeMe() is simply declared in the Sprite class as...

public void NormalizeMe()
{
velocity.Normalize();
}

However, this results in the velocity vector being {X:NaN Y:NaN}, and I'm scratching my head at why this is.
Top of the page Bottom of the page
Kurt Jaegers
Posted 2011-01-06 4:28 AM (#204 - in reply to #203)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(108.16.193.145)
I'll have to go back and look at the book code in detail this weekend, but one thing I usually check for is that Vector.Length is greater than zero before normalizing... if it isn't, you get NaN's for the coordinates after normalization (since normalization divides by the length, normalizing a vector with a length of zero results in a division by zero, which is why the NaN's show up).
Top of the page Bottom of the page
ForgedPixels
Posted 2011-01-07 1:12 PM (#205 - in reply to #204)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 2


(68.149.170.235)
Ah, I was figuring Normalize() would account for that. Adding the length check to that separate NormalizeMe() call makes the normalize work as expected, minimizing the double input speed.
Top of the page Bottom of the page
Windwalker
Posted 2011-09-21 11:33 AM (#348 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 2


(78.181.10.96)
Hello everyone. First off, I would like to thank everyone involved for this great site and the book. I have learnt alot in two months as a newbie to c# and xna, and most of it was due to very well prepared examples and their presentation.

I am currently working on the example which is robot rampage, and things are going smoothly. There is one thing, however, caught my attention both in asteroid belt and in robot rampage and due to me being a fresh vegetable, I can't comprehend it and make it meaningfull with my limited sentience :P

It is about how we call spriteBatch.Draw in sprite classes we created for our projects. What makes me surprised is the way we give the second variable, which is "location" on the screen for the given sprite. We feed it with the "center" of the sprite, which we create a property and a helper method first. Here is the example;

(btw, I am not sure sharing it here would be ok? If it is not, just kill the message and... maybe kill me too..)

public virtual void Draw(SpriteBatch spriteBatch)
{
if(!Expired)
{
if (Camera.ObjectIsVisible(WorldRectangle))
{
spriteBatch.Draw(
Texture,
ScreenCenter,
Source,
tintColor,
rotation,
RelativeCenter,
1.0f,
SpriteEffects.None,
0.0f);

}
}
}

the second piece of info we feed is not the "location" value, which should point to the upper left of the sprite, but it's the center value, which is the location + (length/2, width/2). Thus, the sprite is drawn a little bit lower right of where it should be?

Now I know I am missing something very basic and huge here, but I just can't wrap my head around it. The codes are working, and when I change the "center" to "location" the sprites are drawn slightly to left and up. Nothing else changes... Am I mad? Am I hallucinating?

Did I say thanks?


Edited by Windwalker 2011-09-21 11:35 AM
Top of the page Bottom of the page
Kurt Jaegers
Posted 2011-09-22 3:59 AM (#349 - in reply to #348)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(173.62.195.124)
In order to make the sprite properly rotate around it's center (instead of swinging in a wide arc around the upper left corner) we need to specify the center point (the RelativeCenter in the call you listed). This value offsets the location of the sprite when it is drawn, so we specify the actual center of the location so that it gets subtracted back out when XNA determines where to put it.

That probably sounds fairly confusing, but give it a try in the code... replace ScreenCenter with ScreenLocation and then rotate the sprite... it should seem to orbit around it's upper left corner instead of rotating in place.
Top of the page Bottom of the page
Windwalker
Posted 2011-09-25 7:34 AM (#351 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 2


(78.181.21.79)
Thank you for the answer. The book already says something like this, but what makes me confused is the sixth variable we sent to that particular call, which is the relative center. What I thought was we were sending this relative center information so that XNA can know which point in the sprite we specify as origin point for the turning. Let me (try to) give an example;

We have a spaceship sprite which is 20 by 20 pixels in size.
Location is going to be x:100 y:100;
I also have a helper method, which is called ScreenCenter. It calculates the mid point in the sprite on the screen, so I can tell XNA to rotate from that point, which is called origin, I suppose during Draw call.
It gets the half of sprite length and width and adds it to location. So now;

Location is still x:100 y:100
and
ScreenCenter is x:110 y:110

Our spaceship will start on screen location 100,100 - the top left corner of the sprite will be drawn to there. So when I send the Draw call like this

spriteBatch.Draw(
Texture,
Location,
Source,
tintColor,
ScreenCenter,
1.0f,
SpriteEffects.None,
0.0f);

Now it should draw to 100,100 and rotate from the origin 110,110 shouldnt it? But instead in the previous example we give 100,100 as location point and then we give it an input of 10,10 as relative center? This confuses the hell out of me, even when I try the values on the code.

But now I understand (I think) when you say that XNA subtracts the relative center height and width from the point we give to it as origin and draws the sprite there. I am not entirely sure why it is so but I think I have the tiniest piece of understanding of whats going on now. More trials maybe will make it clearer it for me.

Edited by Windwalker 2011-09-25 7:35 AM
Top of the page Bottom of the page
JayArgh
Posted 2011-10-17 9:39 PM (#356 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 1


(209.6.53.48)
Just came across the same issue that ForgedPixels posted. Finding my way here for a solution was a bit difficult - my first port of call was the Packt page for the book, which lists nothing under Errata. For future reference, is there another centralized location where the book's errata can be found, or does this thread contain all known issues?

Edited by JayArgh 2011-10-17 9:40 PM
Top of the page Bottom of the page
Kurt Jaegers
Posted 2011-11-04 5:57 PM (#366 - in reply to #356)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(96.245.178.53)
So far, there has not been errata for the book. I do try to answer questions here or by e-mail.
Top of the page Bottom of the page
hobbes456
Posted 2012-04-02 6:47 PM (#434 - in reply to #186)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 5


(174.24.178.23)
dupe sorry

Edited by hobbes456 2012-04-02 6:52 PM
Top of the page Bottom of the page
hobbes456
Posted 2012-04-02 6:49 PM (#435 - in reply to #186)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 5


(174.24.178.23)
Hi there!

First off, this book is very cool. I'm new to C#, so it's challenging but I can certainly follow it. However, I'm on chapter 3 and I'm stuck. My game is freezing after I score. This happened after I added the ScoreZoom class. I have gone through the code and couldn't find any errors. I don't get an error at runtime it just shows the scorezoom, updates the score and then won't let me click the pipes anymore.

I went further ahead and added the water, just in case the fix was later on or something. So now I can see the water increasing but I can't move the pipes. I'll attach my Game1 and ScoreZoom. If someone could give me a hand I'd be PUMPED!

EDIT: I can't attach, I'm getting a 500 internal server error? Is that similar to ID10T?

Edited by hobbes456 2012-04-02 6:51 PM
Top of the page Bottom of the page
Kurt Jaegers
Posted 2012-04-03 2:57 AM (#436 - in reply to #435)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(96.245.178.53)
I might not ever have set up the attachment part of the forums If you want to cut and paste the Update method from both classes, that is the most likely place for the issue to be.
Top of the page Bottom of the page
hobbes456
Posted 2012-04-03 7:32 PM (#437 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 5


(174.24.178.23)
I think these are the droids you're looking for?

public void Update()
{
scale += lastScaleAmount + scaleAmount;
lastScaleAmount += scaleAmount;
displayCounter++;
}



private void UpdateFadingPieces()
{
Queue<string> RemoveKeys = new Queue<string>();

foreach (string thisKey in fadingPieces.Keys)
{
fadingPieces[thisKey].UpdatePiece();

if (fadingPieces[thisKey].alphaLevel == 0.0f)
RemoveKeys.Enqueue(thisKey.ToString());
}
while (RemoveKeys.Count > 0)
fadingPieces.Remove(RemoveKeys.Dequeue());
}

private void UpdateFallingPieces()
{
Queue<string> RemoveKeys = new Queue<string>();

foreach (string thisKey in fallingPieces.Keys)
{
fallingPieces[thisKey].UpdatePiece();

if (fallingPieces[thisKey].VerticalOffset == 0)
RemoveKeys.Enqueue(thisKey.ToString());
}

while (RemoveKeys.Count > 0)
fallingPieces.Remove(RemoveKeys.Dequeue());
}

private void UpdateRotatingPieces()
{
Queue<string> RemoveKeys = new Queue<string>();

foreach (string thisKey in rotatingPieces.Keys)
{
rotatingPieces[thisKey].UpdatePiece();

if (rotatingPieces[thisKey].rotationTicksRemaining == 0)
RemoveKeys.Enqueue(thisKey.ToString());
}

while (RemoveKeys.Count > 0)
rotatingPieces.Remove(RemoveKeys.Dequeue());
}

public void UpdateAnimatedPieces()
{
if (fadingPieces.Count == 0)
{
UpdateFallingPieces();
UpdateRotatingPieces();
}
else
{
UpdateFadingPieces();
}
}
Top of the page Bottom of the page
hobbes456
Posted 2012-04-05 5:57 PM (#438 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 5


(174.24.178.23)
Hey Kurt,

Were these the right update methods? See anything wrong?

Thanks!
Top of the page Bottom of the page
Kurt Jaegers
Posted 2012-04-19 2:20 PM (#444 - in reply to #438)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(75.195.148.191)
I don't see anything obviously wrong there... I would have to step through with the debugger to know for sure, though. Can you zip up and e-mail the project files to me? I can be reached at kurt.jaegers@live.com
Top of the page Bottom of the page
sicnhead
Posted 2012-06-05 4:24 AM (#484 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(174.98.94.4)
Hello all I have been working through this great book and have been learning a great deal but am having an issue with the Star Field class. I have double checked the code and am not sure where I'm going wrong but when I start the game just showing the Star Field it initially starts with a line of stars going diagonally across the screen then the stars start to appear as intended. Not sure where I messed this one up at but i have attached my starfield.cs just incase. Thank you in advance for your help.

Scott

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Asteroid_Belt_Assault
{
class StarField
{
private List stars = new List();
private int screenWidth = 800;
private int screenHeight = 600;
private Random rand = new Random();
private Color[] colors = {Color.White, Color.Yellow,
Color.Wheat, Color.WhiteSmoke,
Color.SlateGray};

public StarField(
int screenWidth,
int screenHeight,
int starCount,
Vector2 starVelocity,
Texture2D texture,
Rectangle frameRectangle)
{
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
for (int x = 0; x < starCount; x++
{
stars.Add(new Sprite(new Vector2(
rand.Next(0, screenHeight)),
texture, frameRectangle, starVelocity));
Color starColor = colors[rand.Next(0, colors.Count())];
starColor *= (float)(rand.Next(30, 80) / 100f);
stars[stars.Count() - 1].TintColor = starColor;
}
}

public void Update(GameTime gameTime)
{
foreach (Sprite star in stars)
{
star.Update(gameTime);
if (star.Location.Y > screenHeight)
{
star.Location = new Vector2(
rand.Next(0, screenWidth), 0);
}
}
}

public void Draw(SpriteBatch spriteBatch)
{
foreach (Sprite star in stars)
{
star.Draw(spriteBatch);
}
}
}
}
Top of the page Bottom of the page
thatshaggynerd
Posted 2012-06-05 4:15 PM (#485 - in reply to #186)
Subject: RE: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 2


(64.121.83.242)
From what I can tell your problem is in the for loop in the StarField constructor:


stars.Add(new Sprite(new Vector2(
rand.Next(0, screenHeight)),
texture, frameRectangle, starVelocity));


You aren't passing an x and y valued pair to the new Vector2() call. You should be passing another parameter with the screenWidth referenced:

stars.Add(new Sprite(new Vector2(
rand.Next(0, screenWidth),
rand.Next(0, screenHeight)),
texture, frameRectangle, starVelocity));

That should fix things up. Let me know it didn't!
Top of the page Bottom of the page
sicnhead
Posted 2012-06-07 3:20 AM (#486 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


New user

Posts: 4


(174.98.94.4)
That was it!!! Thank you very much for your help.
Top of the page Bottom of the page
Dieparbaby
Posted 2012-09-18 10:17 PM (#510 - in reply to #186)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 7


(69.171.147.10)
I'm working on the Level Editor in Chapter 8 and I've made it to page 340. The problem I'm having is that if I resize the MapEditor, the tiles in the main area get stretched or shrunk and clicking on the main area does not place the tile in the right location (too far right and/or down if enlarged; too far left and up if shrunk). Has this happened to anyone else or did I just miss adding some code?

Thanks,
Dieparbaby
Top of the page Bottom of the page
Kurt Jaegers
Posted 2012-09-18 10:41 PM (#511 - in reply to #510)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


100100252525

(173.59.14.15)
On pages 325-327, do you have the FixScrollBarScales() method implemented, and being called from the MapEditor_Resize() event handler?
Top of the page Bottom of the page
Dieparbaby
Posted 2012-09-19 6:51 AM (#512 - in reply to #511)
Subject: Re: XNA 4.0 Game Development by Example - Troubleshooting Thread


Member

Posts: 7


(69.171.147.10)
Thanks for replying so quickly.

Yes. I've triple checked both the MapResize event handler and the FixScrollBarScales method and they match the book.
The good news is I compiled the downloaded code and the problem does not occur there. I'll compare the two projects after work
and post the solution if I find it.

Is it possible that an incorrect form control property could cause this? Doesn't seem likely.

Cheers
Top of the page Bottom of the page
Jump to page : 1 2
Now viewing page 1 [25 messages per page]
Jump to forum :
Search this forum
Printer friendly version
E-mail a link to this thread

(Delete all cookies set by this site)
Running MegaBBS ASP Forum Software
© 2002-2014 PD9 Software