Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping logical coordinates to graphical fails when scaling
    primarykey
    data
    text
    <p>I encountered a slight problem with my game's rendering system when I tried to scale certain objects. I think it must be the way I map objects with logical coordinates to graphical ones on the screen.</p> <p><strong>Renderable</strong></p> <pre><code>/** * Retrieve the image representing the object that should be rendered. * @return The image sprite representing the object. */ public Texture getSprite(); /** * Retrieve the x-coordinate where the object should be rendered. * @return The x-coordinate of the object. */ public float getScreenX(); /** * Retrieve the y-coordinate where the object should be rendered. * @return The y-coordinate of the object. */ public float getScreenY(); </code></pre> <p><strong>Texture</strong></p> <pre><code>...... ...... /** * Retrieve the width of the texture. * @return The width of the texture. */ public int getWidth(); /** * Retrieve the height of the texture. * @return The height of the texture. */ public int getHeight(); ...... ...... </code></pre> <p>This system works perfectly when I draw stuff like interfaces etc, which have no logical coordinates in my game world. </p> <p>Let's take a look at an object that have logical coordinates and see how I map the coordinates to graphical ones and thus causing a problem when I scale the texture when drawing.</p> <p><strong>Tile</strong></p> <pre><code>@Override public float getScreenX() { return x * width; } @Override public float getScreenY() { return y * height; } </code></pre> <p>Let's say the size of the texture for any tile is 16*16 but for some reason I want to draw it at 32*32. This will cause a problem since the tile's graphical x- and y-coordinate messes up.</p> <p><strong>Note:</strong> I know that I can fix this by allowing the user to set a scale when loading the image into the system but I want it to be more flexible.</p> <p><strong>TL;DR:</strong> How can I accomplish a better mapping between logical coordinates in the game world to graphical ones while still being able to scale when I want to? There should be a better way to map instead of letting the logical objects be in charge of their graphical coordinates.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload