Can I make a border around an image?
I have lots of blocks in 2D, and when the player hovers with the mouse on one of them I want to display the border around the texture / image.
Thats how I draw the block actually ( I don't think its relevant, but maybe it will help ) :
batch.draw(map.map[mapPos].TEXTURE, (mapPosX * Block.WIDTH), (mapPosY * Block.HEIGHT), Block.WIDTH, Block.HEIGHT);
You could try using a ShapeRenderer to draw the border first, then batch.draw over it. This is done purely in code, without using a texture. The code below adds a blue border.
render() add the following after your
batch.end(); // Add the following after this line sr.setProjectionMatrix(camera.combined); sr.begin(ShapeType.Line); sr.setColor(new Color(0,0,1,0)); sr.rect((mapPosX * Block.WIDTH), (mapPosY * Block.HEIGHT), Block.WIDTH, Block.HEIGHT)); sr.end();
Of course, you need to initialize ShapeRenderer in your
ApplicationListener implementation. Just do it in the code where you declare and initialized batch.
In your Game class:
SpriteBatch batch; //Put the following below this line ShapeRenderer sr;
In your constructor :
batch = new SpriteBatch(); //Put the following below this line sr = new ShapeRenderer();
edit: i have rewrote the function so that you can draw the shape after drawing the texture batch.