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?

  • 1
    \$\begingroup\$ Screenshots would help. \$\endgroup\$
    – Tetrad
    Apr 14, 2011 at 14:58
  • \$\begingroup\$ Added a screenshot :) \$\endgroup\$ Apr 15, 2011 at 1:29

1 Answer 1


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:


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.

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;
  • \$\begingroup\$ 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. \$\endgroup\$ Apr 18, 2011 at 19:35
  • \$\begingroup\$ 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). \$\endgroup\$ Apr 18, 2011 at 20:06
  • \$\begingroup\$ I've fixed the mouse issue, I just had to make a crosshair Texture2D and hid the mouse pointer. Again, thanks for the help :) \$\endgroup\$ Apr 18, 2011 at 20:23
  • \$\begingroup\$ Of course! I'm glad it was of use - and that the solution didn't require many changes :) \$\endgroup\$ Apr 18, 2011 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .