Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My game's source is on github.

I am following this tutorial to create a 2D camera. After I adding the transformation to the SpriteBatch, all of my positions seem to be "off" when I move the ship (and hence camera) away from the screen center.

Any idea what might be wrong?

share|improve this question
1  
Screenshots would help. –  Tetrad Apr 14 '11 at 14:58
    
Added a screenshot :) –  Dylan Nguyen Apr 15 '11 at 1:29
add comment

1 Answer 1

up vote 3 down vote accepted

Since my other answer was incorrect, I deleted it, pulled your source and traced down the actual solution.

The issue is that your particle renderer never gets your camera's transform matrix. Here's how you can fix it:

Update your ParticleManager.Draw method to be the following (very slight change, just the passing of the matrix:

public void Draw(Matrix transform)
{
    foreach (KeyValuePair<string, ParticleEffect> effectPair in particleEffects)
    {
        particleRenderer.RenderEffect(effectPair.Value, ref transform);
    }
}

Then within your ActionScreen.Draw method, make sure to pass along the transformation matrix:

particleManager.Draw(cam.get_transformation(game.GraphicsDevice));

You might want to grab the matrix from the camera earlier in this method, so you don't end up calculating it more than once.

Now comes the annoying part - this alone didn't work for me. I'm guessing it's a bug in the Mercury Particle Engine 3.1. I ended up pulling the source of the current version of Mercury (from their trunk) and compiled it myself. After dropping those assemblies in, the trails and explosions were placed correctly.

For reference, I used Mercury Particle Engine's changeset 87447.

I just looked into the mouse aiming issue and found a quick fix (may want to modify it long-term). In Player.Update, change this:

direction = position - mousePosition;

To this:

direction = new Vector2(Game1.SCREEN_WIDTH * 0.5f, Game1.SCREEN_HEIGHT * 0.5f) - mousePosition;
share|improve this answer
    
Wow, thanks! I'm still having an issue with the ship not pointing towards the mouse though. Only when the ship is in the middle of the screen the aiming works fine, but as soon as I start moving it around the aiming becomes incorrect. –  Dylan Nguyen Apr 18 '11 at 19:35
    
Yeah, I noticed that too. It seems to be an problem going from screen coordinates to game coordinates. Similar issue, but not quite what the question was asking, so I left it for now. If I get a bit of time later, I might look into it and update the question (so long as I find a solution). –  Ryan Versaw Apr 18 '11 at 20:06
    
I've fixed the mouse issue, I just had to make a crosshair Texture2D and hid the mouse pointer. Again, thanks for the help :) –  Dylan Nguyen Apr 18 '11 at 20:23
    
Of course! I'm glad it was of use - and that the solution didn't require many changes :) –  Ryan Versaw Apr 18 '11 at 21:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.