I am working on a simple 2D game with use of Slick2D
But I have one problem that shouldn't be one, but I can't find the correct answer anywhere.
My question is: How can I combine tiles of a spritesheet? One tile is 32 x 32 pixels. I have a sprite for the player that uses 3 tiles in height and one in width. Now I want to display the whole player and I am wondering how I can say that the image of the player goes from tile (3,0) to (3,3) on the sheet.
How I define the spritesheet:
public void init(GameContainer gc) throws SlickException {
spritesheet = new SpriteSheet("res/sprite_sheet.png", 32, 32);
}
How I render it:
public void render(GameContainer gc, Graphics g) throws SlickException {
map.render(200, 100);
g.drawString("Collision: "+collides, 10, 60);
g.draw(pointer);
spritesheet.startUse();
playerImage = //I need to combine them here I guess?
spritesheet.endUse();
playerImage.draw();
}
Thanks for the help :)
After trying around a lot I found out the solution for this.
You can extend yourImageHere.draw() to yourImageHere.draw(x, y, width, height) x and y is the coordinate where your sprite on the image (spritesheet) starts, in pixels width and height defines the size of the image frome there.