How to correctly fill background with a texture android

Anything libgdx related goes here!

How to correctly fill background with a texture android

Postby lastpeony » Wed Sep 04, 2019 7:25 pm

I am trying to fill my games background with a 64x64 tile.But what i did causes black lines to form between them.
I am using
Code: Select all
bgGrass.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);

Code: Select all
  class MyGdxGameDebug():ApplicationAdapter() {
        val SCALE = 2f
        private lateinit var bgGrass: Texture
        var w  = 0
        var h = 0
        lateinit var batch: SpriteBatch
        lateinit var camera: OrthographicCamera
        override fun create() {
            w =
            h =
            camera = OrthographicCamera()
            camera.setToOrtho(false, w/SCALE, h/SCALE);
            batch = SpriteBatch()
            bgGrass= Texture("grass.png")
            bgGrass.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
        override fun render() {
            val uRight = w  / bgGrass.width.toFloat()
            val vTop = h / bgGrass.height.toFloat()
            batch.draw(bgGrass, 0f, 0f,w.toFloat() , h.toFloat(), 0f, 0f, uRight,vTop);
        override fun dispose() {

Here is a image showing black line between tiles:

Posts: 13
Joined: Fri Aug 30, 2019 8:07 pm

Re: How to correctly fill background with a texture android

Postby shatterblast » Sun Sep 08, 2019 6:30 pm

It's not necessary, but you might consider using Tiled. Otherwise, it looks like your black lines are separating in a pattern there, and I'm not sure what to make of it. You might set your uRight and vTop variables to something different, like maybe taking off the "toFloat()" parts on both to see what happens. Starting with Java 11, int has an easier ability than before converting to float, so since Kotlin converts to Java bytecode, I believe you shouldn't need toFloat(). If I am wrong, then it might be a Kotlin nuance unknown to me.

Note: In a very few circumstances with Java 8, it was possible for me to convert from int to float and get a little bit of a 9.000001 or something similar with a tiny trailing number out of it. I have never come across that in Java 11.
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest