I started working through the book Learning Libgdx Game Development and I am wondering if anyone else is currently working or has already finished working through it.
Following the code in the book exactly and compiling the code downloaded that goes with the book, I get small 1-2 pixel gaps between left/right and middle rock graphics and sprites. The problem can be seen here: http://postimg.org/image/rfjdqzund/
This is the code for the rock rendering. I can make the pixel gaps go away by adjusting relX by -0.01f for the left side, 0.01f for the right side and instead of adding + dimension.x for the middle, add dimension.x - 0.01f. I’m not pleased with that solution. I prefer to not use magic numbers and know what’s really going on and how I can fix it.
public void render(SpriteBatch batch)
{
TextureRegion reg = null;
float relX = 0;
float relY = 0;
// draw left edge
reg = regEdge;
relX -= dimension.x / 4;
batch.draw(reg.getTexture(),
position.x + relX, position.y + relY,
origin.x, origin.y,
dimension.x/4, dimension.y,
scale.x, scale.y,
rotation,
reg.getRegionX(), reg.getRegionY(),
reg.getRegionWidth(), reg.getRegionHeight(),
false, false);
// draw middle
relX = 0;
reg = regMiddle;
for (int i = 0; i < length; i++)
{
batch.draw(reg.getTexture(),
position.x + relX, position.y + relY,
origin.x, origin.y,
dimension.x, dimension.y,
scale.x, scale.y,
rotation,
reg.getRegionX(), reg.getRegionY(),
reg.getRegionWidth(), reg.getRegionHeight(),
false, false);
relX += dimension.x;
}
// draw right side
reg = regEdge;
batch.draw(reg.getTexture(),
position.x + relX, position.y + relY,
origin.x + dimension.x / 8, origin.y,
dimension.x/4, dimension.y,
scale.x, scale.y,
rotation,
reg.getRegionX(), reg.getRegionY(),
reg.getRegionWidth(), reg.getRegionHeight(),
true, false);
}
Thanks!