I want to display a semi-transparent texture over the top of my game to create a scanlines effect. The texture is a png with alternating black and transparent lines. To achieve this, I’ve got two problems to overcome:
-
How to create a texture that is the size of the device’s screen resolution, then tile it with my 64x64 scanline png?
-
My game uses an OrthographicCamera to scale the game screen to the size of whatever device it is running on. This means that I can’t simply draw the scanlines texture created in step 1 as I want to scanlines to always be 1 pixel in height of the device’s resolution.
This is what I have so far for problem 1:
Texture texScanlines = globals.spritesAtlas.findRegion("Scanlines").getTexture();
texScanlines.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
TextureRegion imgTextureRegion = new TextureRegion(texScanlines);
imgTextureRegion.setRegion(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
scanlines = new Sprite(imgTextureRegion);
However, this does not work. When creating the Texture using the texture atlas region, the whole texture atlas is being drawn instead of just the selected region. Any pointers?