0
\$\begingroup\$

I have a 2D game made in MonoGame (XNA 4.0 framework). Here's what I want to do:

  • draw a 2d image at a floating point xy coordinate such as 125.5, 300.12 (and do NOT round them to an int).

  • the image is automatically "interlaced", which means the picture is shaded correctly around the borders so that it looks like it's actually a fraction of the way across pixels, and not aligned exactly on pixels.

How do I do this? Is there a standard library for this?

P.S. the game I'm working on eventually needs to work on Mac and Linux as well, so please don't give me any dead-end solutions.

\$\endgroup\$
6
  • \$\begingroup\$ Can you show a (photoshopped) screenshot of the effect you're looking for? Suppose a image consists of a 2x2 white pixel square. What would it look like if it is set at coordinates (1.5 , 1.5) or (1.25, 1,0)? \$\endgroup\$
    – Felsir
    Dec 15, 2015 at 10:27
  • 1
    \$\begingroup\$ Doesn't a SpriteBatch already do something like this by default? \$\endgroup\$ Dec 15, 2015 at 12:28
  • \$\begingroup\$ I think the term you're looking for is "antialiased". The feathering at the edges attempts to correct the spatial aliasing of the sampling grid of the screen. "Interlacing" usually refers to alternating rows of the image being transmitted separately, like old TV signals or progressive loading images on the pre-broadband web. \$\endgroup\$
    – DMGregory
    Dec 15, 2015 at 13:06
  • \$\begingroup\$ @DMGregory "antialiased" might be the right term except it's not just the edges. The whole image must be shifted by that fraction, so interior pixels will get blended somehow too. \$\endgroup\$
    – DrZ214
    Dec 15, 2015 at 21:07
  • \$\begingroup\$ @craftworkgames Yep looks like it does, just didn't realize the Vector2 could take 2 floats because i had wrapped it in my own function. \$\endgroup\$
    – DrZ214
    Dec 15, 2015 at 21:10

1 Answer 1

2
\$\begingroup\$

Any of the Vector2 position draw overloads.

SpriteBatch.Draw (Texture2D, Vector2, Color)
SpriteBatch.Draw (Texture2D, Vector2, Nullable<Rectangle>, Color)
SpriteBatch.Draw (Texture2D, Vector2, Nullable<Rectangle>, Color, Single, Vector2, Single, SpriteEffects, Single)
SpriteBatch.Draw (Texture2D, Vector2, Nullable<Rectangle>, Color, Single, Vector2, Vector2, SpriteEffects, Single)

Combined with any of the filtering options with the exception of Point based ones. (Linear is the default)

TL DR: Use the default sampling state and specify a non integer location in the draw call

\$\endgroup\$
1
  • \$\begingroup\$ Thank you, I must have missed the Vector2 with two floats because a long time ago I wrapped many default draw functions in my own functions that I found more intuitive. \$\endgroup\$
    – DrZ214
    Dec 15, 2015 at 21:09

You must log in to answer this question.

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