Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2008
    Posts
    47

    Strange Mouse Pointer Problems

    I'm having strange problems when using the mouse to aim in my game. I'm making a geometry wars clone (using graphics I got from another game on the internet...this is just a project for school, so I'd say it's fine.) and I decided to use the mouse to aim. Overall, it's kinda glitchy, but the worst problem seems to be that when the loop runs to spawn enemies, it makes the mouse move all over the place. Seeing as how this is the first time I've really created something (mostly) from scratch, my code is probably terrible and convoluted, but I can't find what the problem is.
    Code:
    for (int i = 0; i < maxEnemies; i++)
                {
                    if (flag == true)
                    {
                        if (!enemy[i].isAlive)
                        {
                            if (firstSpawn == true)
                            {
                                //spawnFrame = frameCount;
                                spawnTimer = frameCount;
                                enemyTimeline = new EnemyTimeline(player, enemy, enemyNumber,
                                    waveNumber, enemyTex, flag, numEnemies);
                                enemyNumber++;
                                numEnemies++;
                                firstSpawn = false;
                                //if (flag == false)
                                //enemyNumber = 0;
                                //break;
                            }
                            else
                                if ((frameCount - spawnTimer) > 10)
                                {
                                    if (enemyNumber < maxEnemies)
                                    {
                                        //spawnFrame = frameCount;
                                        enemyNumber++;
                                        numEnemies++;
                                        enemyTimeline = new EnemyTimeline(player, enemy, enemyNumber,
                                            waveNumber, enemyTex, flag, numEnemies);
                                        spawnTimer = frameCount;
                                    }
                                }
                        }
                    }
                    if (numEnemies == 10)
                    {
                        enemyNumber = 0;
                        break;
                    }
                }
    The problem seems to be somewhere in there...or rather, somewhere in the other class, which is right here:
    Code:
                if (waveNumber == 1)
                {
                    if (numEnemies < 10)
                    {
                        numEnemies++;
                        enemy[enemyNumber] = new EnemyData();
                        enemy[enemyNumber].isAlive = true;
                        enemy[enemyNumber].type = 0;
                        enemy[enemyNumber].texture = enemyTex[enemy[enemyNumber].type];
                        enemy[enemyNumber].rotation = 0 + (float)random.NextDouble() * (MathHelper.TwoPi - 0);
                        enemy[enemyNumber].velocity = new Vector2((float)Math.Cos(enemy[enemyNumber].rotation), (float)Math.Sin(enemy[enemyNumber].rotation));
                        enemy[enemyNumber].position = new Vector2(MathHelper.Lerp(10, 50, (float)random.NextDouble()),
                            MathHelper.Lerp(10, 50, (float)random.NextDouble()));
                        flag = false;
                    }
                    else
                        flag = false;
                }
    Thanks a lot, this has become quite a problem for me.

    EDIT: Forgot to add mouse code.

    Forgot to add the code for the mouse. Well...it's kinda all over the place, but this is the main code that finds the position of the mouse:
    Code:
                MouseState mouse = Mouse.GetState();
                mousePos.X = mouse.X;
                mousePos.Y = mouse.Y;
                crosshairPos = mousePos;
    And the crosshair (which will be removed in the final game) is drawn with this:
    Code:
                spriteBatch.Draw(crosshairSpr, crosshairPos,
                    null, Color.White, 0.0f, new Vector2(crosshairSpr.Width, crosshairSpr.Height),
                    0.4f, SpriteEffects.None, 0);
    Guess I'm only really giving part of the picture here...if more code is needed to find the problem, just let me know. Thanks a lot!
    Last edited by Da-Bomb1; 05-28-2009 at 12:12 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    1,215
    From what I can see there your not setting the MousePos anywhere strangely... To double check this, rght-click crosshairPos and Find All References. This will show you everywhere it's used/defined. Maybe your using it somewhere in your code accidentally? (I've done that before, ggrrrrrr)

    Otherwise, mind posting it all in a zip file so we could check it out?

    OR, set a break point in your Enemy-Generation code and follow a game loop, see if you can see whats going on that way

  3. #3
    Join Date
    Aug 2008
    Posts
    47
    Quote Originally Posted by Jacquesy View Post
    From what I can see there your not setting the MousePos anywhere strangely... To double check this, rght-click crosshairPos and Find All References. This will show you everywhere it's used/defined. Maybe your using it somewhere in your code accidentally? (I've done that before, ggrrrrrr)

    Otherwise, mind posting it all in a zip file so we could check it out?

    OR, set a break point in your Enemy-Generation code and follow a game loop, see if you can see whats going on that way
    Well...I tried break points already, and from what I can see, nothing's wrong. It only seems to do this when I'm actually playing the game.

    ...and am I allowed to post the entire file here? I'm not 100% familiar with the rules...I'd gladly post the rest of the file though.

  4. #4
    Join Date
    Jun 2003
    Posts
    434
    yea zip it up so we can see what is happening
    or post a video showing what your talkin about
    My 3DS Max Sprite Sheet Renderer
    A government big enough to give you everything you want,
    is strong enough to take everything you have.
    -- Thomas Jefferson

  5. #5
    Join Date
    Aug 2008
    Posts
    47
    What, this site doesn't let me upload .rar files. Strange. :P Anyway, that's the project right there...unless I'm mistaken, you can just run it from that.
    Attached Files Attached Files

  6. #6
    Join Date
    Jun 2003
    Posts
    434
    The reason it is fubar is because EnemyTimeline extends Game1 there is no need for it to extend anything. Remove that at all should be better also I noticed for the crossHair you are not calculating its origin correctly you need to divide Height and width by 2. also when moving away from the center the aimline no longer points at the mouse and it should. other than that you should be on your way
    My 3DS Max Sprite Sheet Renderer
    A government big enough to give you everything you want,
    is strong enough to take everything you have.
    -- Thomas Jefferson

  7. #7
    Join Date
    Jun 2003
    Posts
    434
    actually I am not sure why Enemytimeline is not a method the class itself does nothing since the constructor is the only thing dealing with data you should probably convert that to a method of your game class or at least based on the rest you have done.
    My 3DS Max Sprite Sheet Renderer
    A government big enough to give you everything you want,
    is strong enough to take everything you have.
    -- Thomas Jefferson

  8. #8
    Join Date
    Aug 2008
    Posts
    47
    Well...at first, I was originally going to have the enemytimeline class do more, but as of right now, the reason why I put it in a separate class was because, since I was going to use a wave-based system, the class could get pretty big. I could just fit it all in the one class, though...but it'd probably start to get kinda unwieldy...at least for me, someone who has barely any experience. Either way, though, I'll try to stick them into the same class and see if it fixes it. Thanks!
    (Although...I still don't really see why it has that strange error. Ah, and also, the crosshair will disappear in the final game...I just wanted it there so I could see what the mouse pointer was doing so I could debug easier.)

  9. #9
    Join Date
    Jun 2003
    Posts
    434
    the reason you had the weird problem is because you extended Game1 which has all the functionality of the game you are making so you have two of everything each running behind each other and every time you instantiated a new "EnemyTimeLine" you were making another copy of sorts which updated another mousePos check etc. It was a rather messy situation for my meager vocabulary to explain. At any rate you had copy after copy of a mousePos initialization and so forth running at the same time.

    you could keep EnemyTimeLine but as it stands right now it does not do much which defeats the purpose of a class. and if you were to keep it you don't to extend anything.

    you could just have

    Code:
    class EnemyTimeLine
    {
         
    }
    My 3DS Max Sprite Sheet Renderer
    A government big enough to give you everything you want,
    is strong enough to take everything you have.
    -- Thomas Jefferson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •