I am trying to understand the example game, cuboc. GitHub is https://github.com/libgdx/libgdx-demo-cuboc. I have generated my texture atlas but I do not understand the code that uses this texture atlas. Here’s the code (you can see on github too here:
package com.badlogic.cubocy;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.SpriteCache;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20;
import com.badlogic.gdx.math.Vector3;
public class MapRenderer {
...
private void createAnimations () {
this.tile = new TextureRegion(new Texture(Gdx.files.internal("data/tile.png")), 0, 0, 20, 20);
Texture bobTexture = new Texture(Gdx.files.internal("data/bob.png"));
TextureRegion[] split = new TextureRegion(bobTexture).split(20, 20)[0];
TextureRegion[] mirror = new TextureRegion(bobTexture).split(20, 20)[0];
for (TextureRegion region : mirror)
region.flip(true, false);
spikes = split[5];
bobRight = new Animation(0.1f, split[0], split[1]);
bobLeft = new Animation(0.1f, mirror[0], mirror[1]);
bobJumpRight = new Animation(0.1f, split[2], split[3]);
bobJumpLeft = new Animation(0.1f, mirror[2], mirror[3]);
bobIdleRight = new Animation(0.5f, split[0], split[4]);
bobIdleLeft = new Animation(0.5f, mirror[0], mirror[4]);
bobDead = new Animation(0.2f, split[0]);
split = new TextureRegion(bobTexture).split(20, 20)[1];
cube = split[0];
cubeFixed = new Animation(1, split[1], split[2], split[3], split[4], split[5]);
split = new TextureRegion(bobTexture).split(20, 20)[2];
cubeControlled = split[0];
spawn = new Animation(0.1f, split[4], split[3], split[2], split[1]);
dying = new Animation(0.1f, split[1], split[2], split[3], split[4]);
dispenser = split[5];
split = new TextureRegion(bobTexture).split(20, 20)[3];
rocket = new Animation(0.1f, split[0], split[1], split[2], split[3]);
rocketPad = split[4];
split = new TextureRegion(bobTexture).split(20, 20)[4];
rocketExplosion = new Animation(0.1f, split[0], split[1], split[2], split[3], split[4], split[4]);
split = new TextureRegion(bobTexture).split(20, 20)[5];
endDoor = split[2];
movingSpikes = split[0];
laser = split[1];
}
What I do not understand is what is split
used for? Like, what is going on here:
split = new TextureRegion(bobTexture).split(20, 20)[1];
And sometimes it looks like split
is a method that takes two int
‘s, 20
and 20
? Why 20?
Othertimes split
is used as an Array
like in …
rocketExplosion = new Animation(0.1f, split[0], split[1], split[2], split[3], split[4], split[4]);
… and I just can’t follow what’s going on here. Thanks!