Hello! I haven’t used this forum that much besides browsing, but I find myself in a bit of a spot here. In a game I’m working on, the character moves around according to “Speed * game.delta”, which is what it’s supposed to be. The problem (and this is mostly a preference thing) is that when my character moves either up or left, he goes slightly faster than right or down, but it might just be appearances. I was just hoping that someone might be able to help me out here.
Github to Code: https://github.com/RyanMB97/Acreage
Classes that might be at fault:
Tiles themselves (DirtTile, GrassTile, StoneTile, etc) in respective classes
Player movement (Player class)
How the level is drawn/updated (Level class)
My own coding style?
Code Itself:
From the “Player” class
public void tick(Game game) {
this.game = game;
bounding.setBounds(x, y, width, height);
speed = 2 * game.delta;
worldEdgeCollision();
movement();
}
private void movement() {
if (game.input.left.down && canLeft) {
game.xOffset -= speed;
directionFacing = 2;
System.out.println(speed);
}
if (game.input.right.down && canRight) {
game.xOffset += speed;
directionFacing = 3;
System.out.println(speed);
}
if (game.input.up.down && canUp) {
game.yOffset -= speed;
directionFacing = 1;
System.out.println(speed);
}
if (game.input.down.down && canDown) {
game.yOffset += speed;
directionFacing = 0;
System.out.println(speed);
}
}
How I Render Tiles in “Level” class
public void renderLevel(Graphics g) {
// Tile loops
for (int y = 0; y < game.worldHeight; y++) {
for (int x = 0; x < game.worldWidth; x++) {
if (tileArray[x][y].x >= game.player.x - (game.getWidth() / 2) - 32 && tileArray[x][y].x <= game.player.x + (game.getWidth() / 2) + 32 & tileArray[x][y].y >= game.player.y - (game.getHeight() / 2) - 32 && tileArray[x][y].y <= game.player.y + (game.getHeight() / 2) + 32) {
tileArray[x][y].render(g);
}
}
} // End loops
} // End render
The rendering method itself is a bit odd, since I tossed it together on the spot. In brief explanation, it doesn’t render tiles that are off of the viewable screen, plus 1 more for more seamless viewing while moving.
An example of a tile being drawn, “DirtTile” class
public void tick(Game game) {
this.game = game;
x = oX - game.xOffset; // Current x after movement, Offset, etc
y = oY - game.yOffset; // Current y after movement, Offset, etc
bounding = new Rectangle(x, y, size, size);
bounding.setBounds(x, y, size, size);
}
public void render(Graphics g) {
g.drawImage(game.res.tiles[tileID], x, y, game);
if (game.showGrid) { // If the player wants to draw grids
g.setColor(Color.WHITE); // White color
g.drawRect(x, y, size - 1, size - 1); // Draw a border around tile
}
if (showBorders) { // If it is allowed to show borders
g.setColor(Color.BLACK); // White color
g.drawRect(x, y, size - 1, size - 1); // Draw a border around image
}
}
Sorry if the thread is a bit long, but this is really bothering me. Also, any advice or information to anything not of this topic is much appreciated. Thanks in advance for any and all responses!