Hello everyone, I’m new here
So I am currently working on a 2D Isometric-diamond Zombie survival game.
I have followed this guide for having a solid base: http://www.java-gaming.org/topics/basic-game/21919/view.html
My first problem is when I move my character my game renders white lines between the tiles like small render lags.
First problem kinda solved: I tried to increase increase the mapXOffset by deltaTime * 0.2 in each update and it removed all the white lines.
Though somehow I still think I’m doing it wrong by moving the mapXOffset instead of the player and now I have to somehow when I press the arrows keys they have to go to the update method hmm.
My plan is to keep the player in the center of the screen all the time, currently the player is the small black rectangle
The tiles graphic is both within a tilesheet.png
My tilemap array
//Tile map
int[][] tileMap_array = new int[][] {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
{0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1}
};
Rendering the map and player
for (int i=0; i<tileMap_array.length; i++)
{
for (int j=(tileMap_array[i].length-1); j>=0; j--)
{
if (tileMap_array[i][j] == 1)
{
//Getting subimage of tilesheet
g.drawImage(tileMap_img.getSubimage(0, 32, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
}
else
{
g.drawImage(tileMap_img.getSubimage(0, 0, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth())/2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
}
}
}
g.setColor(Color.black);
g.fillRect(player.x, player.y, 10, 10);
When the player clicks an arrow key its not the player moving but the world around him.
int mapXOffset;
int mapYOffset;
So when the player clicks an arrow key I change the value of one of the map offsets
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if (e.getKeyCode() == 37)
{
//Left arrow
mapXOffset -= 5;
}
else if (e.getKeyCode() == 38)
{
//Up arrow
mapYOffset += 5;
}
else if (e.getKeyCode() == 39)
{
//Right arrow
mapXOffset += 5;
}
else if (e.getKeyCode() == 40)
{
//Down arrow
mapYOffset -= 5;
}
}
I have two guesses, either its doing the small white lines because I has to re-render the whole world each time or its because I’m doing the variable changing within the code above and not using the the deltatime within my update method
protected void update(int deltaTime)
{
}
My second question is: How could I go about making collisions? I plan to put in objects, even interactive objects like doors and so on.
My third question is: When the player is close to a staircase how could I simulate he is walking up on the staircase to the next floor inside a building?
And ofcourse if there is any tip/advice where I could do something better, please say so.
Thanks in advance.