| ||
![]() | ||
|
| You are logged in as a guest. ( logon | register ) |
XNA 4.0 Game Development by Example - Troubleshooting ThreadJump to page : 1 2 Now viewing page 1 [25 messages per page] | View previous thread :: View next thread |
| General Discussion -> General Discussion | Message format |
| rlsl88 |
| ||
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. | ||
| |||
| rlsl88 |
| ||
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 ---------------- Game1.cs (13KB - 1 downloads) | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (108.16.193.145) | All of these errors seem to reference the ScoreZoom class. Can you post what you have for ScoreZoom? | ||
| |||
| rlsl88 |
| ||
New user Posts: 4 (76.169.200.213) | Thanks for the help. ScoreZoom.cs is attached. Attachments ---------------- ScoreZoom.cs (1KB - 0 downloads) | ||
| |||
| rlsl88 |
| ||
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. | ||
| |||
| ForgedPixels |
| ||
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. | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (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). | ||
| |||
| ForgedPixels |
| ||
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. | ||
| |||
| Windwalker |
| ||
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 | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (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. | ||
| |||
| Windwalker |
| ||
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 | ||
| |||
| JayArgh |
| ||
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 | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (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. | ||
| |||
| hobbes456 |
| ||
Member Posts: 5 (174.24.178.23) | dupe sorry Edited by hobbes456 2012-04-02 6:52 PM | ||
| |||
| hobbes456 |
| ||
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 | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (96.245.178.53) | I might not ever have set up the attachment part of the forums | ||
| |||
| hobbes456 |
| ||
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(); } } | ||
| |||
| hobbes456 |
| ||
Member Posts: 5 (174.24.178.23) | Hey Kurt, Were these the right update methods? See anything wrong? Thanks! | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (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 | ||
| |||
| sicnhead |
| ||
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); } } } } | ||
| |||
| thatshaggynerd |
| ||
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! | ||
| |||
| sicnhead |
| ||
New user Posts: 4 (174.98.94.4) | That was it!!! Thank you very much for your help. | ||
| |||
| Dieparbaby |
| ||
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 | ||
| |||
| Kurt Jaegers |
| ||
![]() ![]() ![]() ![]() ![]() (173.59.14.15) | On pages 325-327, do you have the FixScrollBarScales() method implemented, and being called from the MapEditor_Resize() event handler? | ||
| |||
| Dieparbaby |
| ||
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 | ||
| |||
| Jump to page : 1 2 Now viewing page 1 [25 messages per page] |
| 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-2013 PD9 Software | |

XNA 4.0 Game Development by Example - Troubleshooting Thread