0
\$\begingroup\$

I apologize if this has been answered somewhere; I spent quite awhile searching but couldn't find an answer.

I have any issue with my 2D sprites being drawn to the screen - either the non-moving or moving sprites will appear to have a sort of "fuzzy" texture to them. Now, this isn't an issue with me drawing to integer positions - after a bit of debugging, I found out this was an issue with my camera - it'll jump between, say, (79, 179) and (81, 181). The number is arbitrary, but it's always two pixels.

The camera follows the player's sprite, unless the player happens to be near the edge of the map - in which case, the player can move freely without the camera chasing it (so the camera doesn't show the void space outside the world). During this "free roam" space, when moving, the static entities/sprites appear normal, but the player's sprite appears fuzzy (and if the camera is following the player, the static entities appear fuzzy while the player entity appears normal). If I get the player to move around enough, what happens is that I'll be able to see the console printing out the odd values for the camera's position (as stated earlier).

My camera's update code:

    public void Update(Entity followEntity)
    {
        Vector2 moveToPos = new Vector2((int)followEntity.Position.X - 400, (int)followEntity.Position.Y - 300);
        Console.WriteLine(position);
        position = Vector2.Clamp(moveToPos, MinBounds, MaxBounds);
        transform = Matrix.CreateTranslation(-position.X, -position.Y, 0);

        inverseTransform = Matrix.Invert(transform);
    }

My player's update code automatically casts its position to an int (since Vector2's are stored in floats), but I cast it explicitly in this code while I was debugging. I also tried setting position's x and y values to ints after it clamps the value, but that didn't have any effect.

In case it helps, my draw method is as follows:

   protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, playerCamera.Transform);
        tileMap.Draw(spriteBatch);

        foreach (Entity e in Entity.LiveEntityList)
            e.Draw(spriteBatch);

        spriteBatch.End();
        base.Draw(gameTime);
    }

If there's anything information I could add to help you help me, please let me know. Thank you for your time!

Edit: the - 400 and - 300 values in my camera's update code are purely hardcoded values to determine the center of the screen since I was running it in 800x600, in case anyone was curious or needed to know.

As requested, a screenshot:

jittery movement

You can see the corners of the two squares slightly overlapping; it bounces between this and being one pixel away. The desired behavior would look as follows:

desired behavior

\$\endgroup\$
7
  • \$\begingroup\$ Would it be possible to include sample images of the blurry draws? \$\endgroup\$
    – jgallant
    Jul 2, 2014 at 20:08
  • \$\begingroup\$ Edited to include a sample image. Let me know if there's anything else that'd help! \$\endgroup\$
    – Sheer
    Jul 2, 2014 at 20:55
  • \$\begingroup\$ Have you tried NOT casting the floats to ints? I suspect your attempts to clamp the values are only making the situation worse. For example, if the corners of your boxes are X = 10.1 and X = 10.9 respectively, you're actually drawing them both at X = 10 since an (int) cast truncates the decimal points off. \$\endgroup\$ Jul 3, 2014 at 1:13
  • \$\begingroup\$ I have; issue remains unaffected. If it's of any use, movement is based on 32x32 tiles, so the player moves in blocks rather than pixel-by-pixel. \$\endgroup\$
    – Sheer
    Jul 3, 2014 at 1:54
  • \$\begingroup\$ To clarify on that: I mean the player moves between 32x32 blocks; they cannot move to a pixel that is not a multiple of 32. Imagine a Pokemon game, but with clicking your mouse instead of WASD or the arrow keys to move. \$\endgroup\$
    – Sheer
    Jul 3, 2014 at 2:14

0

You must log in to answer this question.

Browse other questions tagged .