use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class TmxMapLoader method load.
/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
* constructor of this class. By default it will resolve to an internal file.
* @param fileName the filename
* @param parameters specifies whether to use y-up, generate mip maps etc.
* @return the TiledMap */
public TiledMap load(String fileName, TmxMapLoader.Parameters parameters) {
try {
this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
this.flipY = parameters.flipY;
FileHandle tmxFile = resolve(fileName);
root = xml.parse(tmxFile);
ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
textureFiles.addAll(loadImages(root, tmxFile));
for (FileHandle textureFile : textureFiles) {
Texture texture = new Texture(textureFile, parameters.generateMipMaps);
texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
textures.put(textureFile.path(), texture);
}
DirectImageResolver imageResolver = new DirectImageResolver(textures);
TiledMap map = loadTilemap(root, tmxFile, imageResolver);
map.setOwnedResources(textures.values().toArray());
return map;
} catch (IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class OrthoCachedTiledMapRenderer method renderTileLayer.
@Override
public void renderTileLayer(TiledMapTileLayer layer) {
final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());
final int layerWidth = layer.getWidth();
final int layerHeight = layer.getHeight();
final float layerTileWidth = layer.getTileWidth() * unitScale;
final float layerTileHeight = layer.getTileHeight() * unitScale;
final float layerOffsetX = layer.getOffsetX() * unitScale;
// offset in tiled is y down, so we flip it
final float layerOffsetY = -layer.getOffsetY() * unitScale;
final int col1 = Math.max(0, (int) ((cacheBounds.x - layerOffsetX) / layerTileWidth));
final int col2 = Math.min(layerWidth, (int) ((cacheBounds.x + cacheBounds.width + layerTileWidth - layerOffsetX) / layerTileWidth));
final int row1 = Math.max(0, (int) ((cacheBounds.y - layerOffsetY) / layerTileHeight));
final int row2 = Math.min(layerHeight, (int) ((cacheBounds.y + cacheBounds.height + layerTileHeight - layerOffsetY) / layerTileHeight));
canCacheMoreN = row2 < layerHeight;
canCacheMoreE = col2 < layerWidth;
canCacheMoreW = col1 > 0;
canCacheMoreS = row1 > 0;
float[] vertices = this.vertices;
for (int row = row2; row >= row1; row--) {
for (int col = col1; col < col2; col++) {
final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
if (cell == null)
continue;
final TiledMapTile tile = cell.getTile();
if (tile == null)
continue;
count++;
final boolean flipX = cell.getFlipHorizontally();
final boolean flipY = cell.getFlipVertically();
final int rotations = cell.getRotation();
final TextureRegion region = tile.getTextureRegion();
final Texture texture = region.getTexture();
final float x1 = col * layerTileWidth + tile.getOffsetX() * unitScale + layerOffsetX;
final float y1 = row * layerTileHeight + tile.getOffsetY() * unitScale + layerOffsetY;
final float x2 = x1 + region.getRegionWidth() * unitScale;
final float y2 = y1 + region.getRegionHeight() * unitScale;
final float adjustX = 0.5f / texture.getWidth();
final float adjustY = 0.5f / texture.getHeight();
final float u1 = region.getU() + adjustX;
final float v1 = region.getV2() - adjustY;
final float u2 = region.getU2() - adjustX;
final float v2 = region.getV() + adjustY;
vertices[X1] = x1;
vertices[Y1] = y1;
vertices[C1] = color;
vertices[U1] = u1;
vertices[V1] = v1;
vertices[X2] = x1;
vertices[Y2] = y2;
vertices[C2] = color;
vertices[U2] = u1;
vertices[V2] = v2;
vertices[X3] = x2;
vertices[Y3] = y2;
vertices[C3] = color;
vertices[U3] = u2;
vertices[V3] = v2;
vertices[X4] = x2;
vertices[Y4] = y1;
vertices[C4] = color;
vertices[U4] = u2;
vertices[V4] = v1;
if (flipX) {
float temp = vertices[U1];
vertices[U1] = vertices[U3];
vertices[U3] = temp;
temp = vertices[U2];
vertices[U2] = vertices[U4];
vertices[U4] = temp;
}
if (flipY) {
float temp = vertices[V1];
vertices[V1] = vertices[V3];
vertices[V3] = temp;
temp = vertices[V2];
vertices[V2] = vertices[V4];
vertices[V4] = temp;
}
if (rotations != 0) {
switch(rotations) {
case Cell.ROTATE_90:
{
float tempV = vertices[V1];
vertices[V1] = vertices[V2];
vertices[V2] = vertices[V3];
vertices[V3] = vertices[V4];
vertices[V4] = tempV;
float tempU = vertices[U1];
vertices[U1] = vertices[U2];
vertices[U2] = vertices[U3];
vertices[U3] = vertices[U4];
vertices[U4] = tempU;
break;
}
case Cell.ROTATE_180:
{
float tempU = vertices[U1];
vertices[U1] = vertices[U3];
vertices[U3] = tempU;
tempU = vertices[U2];
vertices[U2] = vertices[U4];
vertices[U4] = tempU;
float tempV = vertices[V1];
vertices[V1] = vertices[V3];
vertices[V3] = tempV;
tempV = vertices[V2];
vertices[V2] = vertices[V4];
vertices[V4] = tempV;
break;
}
case Cell.ROTATE_270:
{
float tempV = vertices[V1];
vertices[V1] = vertices[V4];
vertices[V4] = vertices[V3];
vertices[V3] = vertices[V2];
vertices[V2] = tempV;
float tempU = vertices[U1];
vertices[U1] = vertices[U4];
vertices[U4] = vertices[U3];
vertices[U3] = vertices[U2];
vertices[U2] = tempU;
break;
}
}
}
spriteCache.add(texture, vertices, 0, NUM_VERTICES);
}
}
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class ContainerTest method create.
@Override
public void create() {
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
stage = new Stage();
Gdx.input.setInputProcessor(stage);
TextureRegionDrawable logo = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("data/badlogic.jpg"))));
Table root = new Table();
root.setFillParent(true);
root.debug().defaults().space(6).size(110);
stage.addActor(root);
root.add(new Container(label("center")));
root.add(new Container(label("top")).top());
root.add(new Container(label("right")).right());
root.add(new Container(label("bottom")).bottom());
root.add(new Container(label("left")).left());
root.row();
root.add(new Container(label("fill")).fill());
root.add(new Container(label("fillX")).fillX());
root.add(new Container(label("fillY")).fillY());
root.add(new Container(label("fill 75%")).fill(0.75f, 0.75f));
root.add(new Container(label("fill 75% br")).fill(0.75f, 0.75f).bottom().right());
root.row();
root.add(new Container(label("padTop 5\ntop")).padTop(5).top());
root.add(new Container(label("padBottom 5\nbottom")).padBottom(5).bottom());
root.add(new Container(label("padLeft 15")).padLeft(15));
root.add(new Container(label("pad 10 fill")).pad(10).fill());
root.add(new Container(label("pad 10 tl")).pad(10).top().left());
root.row();
root.add(new Container(label("bg")).background(logo));
root.add(new Container(label("bg height 50")).background(logo).height(50));
Container transformBG = new Container(label("bg transform")).background(logo);
transformBG.setTransform(true);
transformBG.setOrigin(55, 55);
transformBG.rotateBy(90);
root.add(transformBG);
Container transform = new Container(label("transform"));
transform.setTransform(true);
transform.setOrigin(55, 55);
transform.rotateBy(90);
root.add(transform);
Container clip = new Container(label("clip1clip2clip3clip4"));
clip.setClip(true);
root.add(clip);
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class CpuSpriteBatchTest method create.
public void create() {
Batch batch = new CpuSpriteBatch();
// batch = new SpriteBatch();
stage = new Stage(new ExtendViewport(500, 500), batch);
Gdx.input.setInputProcessor(stage);
texture = new Texture("data/bobargb8888-32x32.png");
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
for (int i = 0; i < NUM_GROUPS; i++) {
Group group = createActorGroup(drawable);
stage.addActor(group);
}
}
use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.
the class CustomShaderSpriteBatchTest method create.
@Override
public void create() {
batch = new SpriteBatch(10);
ShaderProgram.pedantic = false;
shader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/batch.frag").readString());
batch.setShader(shader);
texture = new Texture("data/badlogic.jpg");
}
Aggregations