3
\$\begingroup\$

From the Godot feature list:

Work in pixels as your units, but scale to any screen size and ratio.

Reading the documentation they also use pixel coordinates to update the position of objects

move( Vector2(0,1) ) #move down 1 pixel per physics frame

What is the advantage of using pixel coordinates? The limitation seems to be that an object can't easily move less than one pixel per frame. For example move object 1.5 pixels per frame.

\$\endgroup\$
  • \$\begingroup\$ Who is Godot and why are you so sure that he means your pixel-coordinates must be integers and not floating-point values? \$\endgroup\$ – Philipp Feb 23 '16 at 18:27
  • \$\begingroup\$ @Philipp Added the link and to answer your second question, it makes no sense to use floats for pixel coordinates. Pixels are absolute, there are no pixels between pixels. \$\endgroup\$ – Maik Klein Feb 23 '16 at 18:34
  • 3
    \$\begingroup\$ ...you mean except in the case you mentioned in your question where an object moves 1.5 pixels per frame? If you want to avoid interpolation you often keep coordinates in floating-point in your game mechanics but round to the nearest integer when rendering. \$\endgroup\$ – Philipp Feb 23 '16 at 18:38
4
\$\begingroup\$

...you mean except in the case you mentioned in your question where an object moves 1.5 pixels per frame? If you want to avoid interpolation you often keep coordinates in floating-point in your game mechanics but round to the nearest integer when rendering. - Philipp

This boils down to being more convenient for humans. Why make it more complicated than it must be?

As an example, if you wanted to sample a texture directly beneath the mouse cursor:

Texture.Sample((MouseCoordinate.x + 1) / TextureWidth, MouseCoordinate.y / TextureHeight)  
or  
Texture.Load(MouseCoordinate.x + 1, MouseCoordinate.y)

Depending on the sampler state in use, both sample the same location.

Player movement:

//UINT coordinates
UINT PlayerPositionX += 0.456322f; //Camera doesn't move fast enough to increment
UINT PlayerPositionX += (UINT)0.456322f;
UINT PlayerPositionX += 0;
//All equivalent

//float (CPU) coordinates
float PlayerPositionX += 0.456322f;
then
UINT RenderPlayerAtX = round(PlayerPositionX); //Round
or
UINT RenderPlayerAtX = trunc(PlayerPositionX); //Always round down
or
UINT RenderPlayerAtX = ceil(PlayerPositionX); //Always round up

By drawing integer-pixel-sized sprites at integer locations, no portion of the objects (especially the edges along its' boundary) will fall in-between two pixels. Depending on the fractional part of the sprites location, the pixel that should be the left-most pixel of your sprite may output no color, distorting the sprites visual size.

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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