I am using scene2d in libGDX on Android as part of a game I am working on. I have a simple splash screen, which I am trying to display a single image on. The image comes from a file with two tiles in it, and I am using TextureRegion.split() to access it. My problem is, the entire image gets displayed instead of just the first tile.
Here are code snippets to illustrate what I am doing. You should be able to put this in a basic libGDX app to test it out. The image I am using is a png with dimensions of 460 width X 342, (2 tiles of 460X171). I am using the latest libGDX, as obtained from the libGDX setup tool.
What is wrong with my code?
TextureRegion tiles = new TextureRegion( new Texture( Gdx.files.internal( "foo.png" ) ) ) .split( 460, 171 ); Stage stage; Table table; stage = new Stage(); table = new Table(); table.setFillParent(true); stage.addActor(table); Texture fooTex = tiles[ 0 ][ 0 ].getTexture(); Image fooImg = new Image( fooTex ); fooImg.setPosition( ( Gdx.graphics.getWidth() / 2 ) - ( fooImg.getWidth() / 2 ), ( Gdx.graphics.getHeight() / 2 ) - ( fooImg.getHeight() / 2 ) ); stage.addActor( fooImg );