List of usage examples for com.badlogic.gdx.graphics.g2d TextureAtlas getTextures
public ObjectSet<Texture> getTextures()
From source file:com.alma42.mapgen.game.Assets.java
License:Apache License
public void init(final AssetManager assetManager) { this.assetManager = assetManager; // set asset manager error handler assetManager.setErrorListener(this); // load texture atlas assetManager.load(Constants.TEXTURE_ATLAS_OBJECTS, TextureAtlas.class); // start loading assets and wait until finished assetManager.finishLoading();//from w ww . j a v a 2 s .co m Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size); for (final String a : assetManager.getAssetNames()) { Gdx.app.debug(TAG, "asset: " + a); } final TextureAtlas atlas = assetManager.get(Constants.TEXTURE_ATLAS_OBJECTS); // enable texture filtering for pixel smoothing for (final Texture t : atlas.getTextures()) { t.setFilter(TextureFilter.Linear, TextureFilter.Linear); } // create game resource objects this.bunny = new AssetBunny(atlas); this.rock = new AssetRock(atlas); this.goldCoin = new AssetGoldCoin(atlas); this.feather = new AssetFeather(atlas); this.levelDecoration = new AssetLevelDecoration(atlas); }
From source file:com.github.fauu.helix.core.MapRegion.java
License:Open Source License
public void create(Vector2 size, Tile[] tiles, Array<Object> objects, TextureAtlas textureAtlas, GeometrySet geometrySet) {// www . jav a 2s .co m this.size = size; this.textureAtlas = textureAtlas; this.geometrySet = geometrySet; this.objects = objects; if (tiles != null) { this.tiles = tiles; } else { final int tilesLength = (int) (size.x * size.y); tiles = new Tile[tilesLength]; for (int i = 0; i < tilesLength; i++) { final Tile.Builder tileBuilder = new Tile.Builder(); final int tileX = i % (int) size.x; final int tileY = (int) Math.floor(i / (tilesLength / size.y)); tiles[i] = tileBuilder.setNo(i).setPosition(new Vector2(tileX, tileY)).setElevation(0) .setTextureId(0).setGeometryId(0).setFacing(Direction.SOUTH).build(); } } this.tiles = tiles; mesh = new MapRegionMesh(tiles, geometrySet, textureAtlas); renderable = new Renderable(); renderable.mesh = mesh; renderable.material = new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE), new TextureAttribute(TextureAttribute.Diffuse, textureAtlas.getTextures().first())); renderable.meshPartOffset = 0; renderable.meshPartSize = mesh.getNumVertices(); renderable.primitiveType = GL20.GL_TRIANGLES; renderable.worldTransform.idt(); }
From source file:com.github.fauu.helix.editor.displayable.TilePermissionsGridDisplayable.java
License:Open Source License
public TilePermissionsGridDisplayable(Tile[][] tiles, TextureAtlas atlas) { this.atlas = atlas; MeshBuilder meshBuilder = new MeshBuilder(); meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates, GL20.GL_TRIANGLES);/*from ww w.j ava 2 s. c o m*/ for (int y = 0; y < tiles.length; y++) { for (int x = 0; x < tiles[y].length; x++) { // TODO: Cache regions meshBuilder.setUVRange(atlas.findRegion(tiles[y][x].getPermissions().name())); meshBuilder.rect(x, y, 0, x + 1, y, 0, x + 1, y + 1, 0, x, y + 1, 0, 0, 0, 1); } } Mesh mesh = meshBuilder.end(); ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); TextureAttribute diffuse = TextureAttribute.createDiffuse(atlas.getTextures().first()); modelBuilder.part("grid", mesh, GL20.GL_TRIANGLES, new Material(diffuse)); instance = new ModelInstance(modelBuilder.end()); instance.transform.translate(0, 0, Z_OFFSET); }
From source file:com.kotcrab.vis.editor.module.project.TextureCacheModule.java
License:Apache License
private TextureRegion getAtlasRegion(AtlasRegionAsset asset) { String relativePath = asset.getPath(); TextureAtlas atlas = atlases.get(relativePath); if (atlas == null) return missingRegion; if (asset.getRegionName() == null) { return new TextureRegion(atlas.getTextures().first()); } else {// www. j av a 2 s . c o m TextureRegion region = atlas.findRegion(asset.getRegionName()); if (region == null) return missingRegion; return region; } }
From source file:com.ntr.prototype.game.Assets.java
public void init(AssetManager assetManager) { this.assetManager = assetManager; assetManager.setErrorListener(this); assetManager.load(Constants.ATLAS_OBJECT, TextureAtlas.class); //not completed assetManager.finishLoading();/*from w w w .j ava2 s . co m*/ Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size); for (String a : assetManager.getAssetNames()) { Gdx.app.debug(TAG, "assets : " + a); } TextureAtlas atlas = assetManager.get(Constants.ATLAS_OBJECT); for (Texture t : atlas.getTextures()) { t.setFilter(TextureFilter.Linear, TextureFilter.Linear); } catcher = new AssetCatcher(atlas); decoration = new AssetDecoration(atlas); gas = new AssetGas(atlas); background = new AssetBackground(atlas); }
From source file:com.packtpub.libgdx.canyonbunny.game.Assets.java
License:Apache License
public void init(AssetManager assetManager) { this.assetManager = assetManager; // set asset manager error handler assetManager.setErrorListener(this); // load texture atlas assetManager.load(Constants.TEXTURE_ATLAS_OBJECTS, TextureAtlas.class); // start loading assets and wait until finished assetManager.finishLoading();//w w w .j a v a2 s .c o m Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size); for (String a : assetManager.getAssetNames()) { Gdx.app.debug(TAG, "asset: " + a); } TextureAtlas atlas = assetManager.get(Constants.TEXTURE_ATLAS_OBJECTS); // enable texture filtering for pixel smoothing for (Texture t : atlas.getTextures()) { t.setFilter(TextureFilter.Linear, TextureFilter.Linear); } // create game resource objects fonts = new AssetFonts(); bunny = new AssetBunny(atlas); rock = new AssetRock(atlas); goldCoin = new AssetGoldCoin(atlas); feather = new AssetFeather(atlas); levelDecoration = new AssetLevelDecoration(atlas); }
From source file:core.september.foundation.Assets.java
License:Apache License
public void init(AssetManager assetManager) { this.assetManager = assetManager; // set asset manager error handler assetManager.setErrorListener(this); // load texture atlas assetManager.load(Constants.TEXTURE_ATLAS_OBJECTS, TextureAtlas.class); assetManager.load("sounds/engine_on.wav", Sound.class); assetManager.load("sounds/level_switch.wav", Sound.class); assetManager.load("sounds/push_button.wav", Sound.class); assetManager.load("music/soundtrack.mp3", Music.class); // start loading assets and wait until finished assetManager.finishLoading();/* w w w . j av a 2s . co m*/ Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size); for (String a : assetManager.getAssetNames()) { Gdx.app.debug(TAG, "asset: " + a); } TextureAtlas atlas = assetManager.get(Constants.TEXTURE_ATLAS_OBJECTS); // enable texture filtering for pixel smoothing for (Texture t : atlas.getTextures()) { t.setFilter(TextureFilter.Linear, TextureFilter.Linear); } // create game resource objects sounds = new AssetSounds(assetManager); assetMusic = new AssetMusic(assetManager); button = new AssetButton(atlas); background = new AssetBackground(atlas); countdown = new AssetCountDown(atlas); powerButton = new AssetPowerButton(atlas); led = new AssetLed(atlas); assetUi = new AssetUi(atlas); knob = new AssetSoundKnob(atlas); assetHelp = new AssetHelp(atlas); assetSkin = new AssetSkin(atlas); fonts = new AssetFonts(); }
From source file:de.bitowl.advent.game2.MyAtlasTmxMapLoader.java
License:Apache License
protected void loadTileset(TiledMap map, Element element, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) { if (element.getName().equals("tileset")) { String name = element.get("name", null); int firstgid = element.getIntAttribute("firstgid", 1); int tilewidth = element.getIntAttribute("tilewidth", 0); int tileheight = element.getIntAttribute("tileheight", 0); int spacing = element.getIntAttribute("spacing", 0); int margin = element.getIntAttribute("margin", 0); String source = element.getAttribute("source", null); String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null;/*from www . j a va 2 s . c om*/ if (source != null) { FileHandle tsx = getRelativeFileHandle(tmxFile, source); try { element = xml.parse(tsx); name = element.get("name", null); tilewidth = element.getIntAttribute("tilewidth", 0); tileheight = element.getIntAttribute("tileheight", 0); spacing = element.getIntAttribute("spacing", 0); margin = element.getIntAttribute("margin", 0); imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } if (!map.getProperties().containsKey("atlas")) { throw new GdxRuntimeException("The map is missing the 'atlas' property"); } // get the TextureAtlas for this tileset FileHandle atlasHandle = getRelativeFileHandle(tmxFile, map.getProperties().get("atlas", String.class)); atlasHandle = resolve(atlasHandle.path()); TextureAtlas atlas = resolver.getAtlas(atlasHandle.path()); //String regionsName = atlasHandle.nameWithoutExtension(); String regionsName = name; if (parameter != null && parameter.forceTextureFilters) { for (Texture texture : atlas.getTextures()) { trackedTextures.add(texture); } } TiledMapTileSet tileset = new TiledMapTileSet(); MapProperties props = tileset.getProperties(); tileset.setName(name); props.put("firstgid", firstgid); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); props.put("imageheight", imageHeight); props.put("tilewidth", tilewidth); props.put("tileheight", tileheight); props.put("margin", margin); props.put("spacing", spacing); Array<AtlasRegion> regions = atlas.findRegions(regionsName); System.out.println(regions.size); for (AtlasRegion region : regions) { // handle unused tile ids if (region != null) { StaticTiledMapTile tile = new StaticTiledMapTile(region); if (!yUp) { region.flip(false, true); } int tileid = firstgid + region.index; tile.setId(tileid); tileset.putTile(tileid, tile); System.out.println("put tile " + tileid); } } Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { String terrain = tileElement.getAttribute("terrain", null); if (terrain != null) { tile.getProperties().put("terrain", terrain); } String probability = tileElement.getAttribute("probability", null); if (probability != null) { tile.getProperties().put("probability", probability); } Element properties = tileElement.getChildByName("properties"); if (properties != null) { loadProperties(tile.getProperties(), properties); } } } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } System.out.println("add tileset to map: " + tileset.getName()); map.getTileSets().addTileSet(tileset); } }
From source file:headmade.arttag.assets.Assets.java
License:Apache License
/** * // enable texture filtering for pixel smoothing * * @param atlas/* ww w. j av a2s .co m*/ * @param typeOfFilter */ private void setTextureFilter(TextureAtlas atlas, TextureFilter typeOfFilter) { Gdx.app.log(TAG, "setting filter for textures " + atlas.getTextures().size); for (final Texture t : atlas.getTextures()) { t.setFilter(typeOfFilter, typeOfFilter); // min=mag } final Skin skin = assetsManager.get(AssetTextures.skin, Skin.class); final BitmapFont font = skin.getFont("default-font"); for (int i = 0; i < font.getRegions().size; i++) { font.getRegion(i).getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); } NinePatch ninepatch = skin.get(AssetTextures.frame, NinePatch.class); ninepatch.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); ninepatch.scale(ArtTag.UNIT_SCALE * 0.75f, ArtTag.UNIT_SCALE * 0.75f); ninepatch = skin.get(AssetTextures.frame2, NinePatch.class); ninepatch.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); ninepatch.scale(ArtTag.UNIT_SCALE / 3, ArtTag.UNIT_SCALE / 3); }
From source file:headmade.ld34.Assets.java
License:Apache License
/** * // enable texture filtering for pixel smoothing * * @param atlas//from www . j a va2 s . co m * @param typeOfFilter */ private void setTextureFilter(TextureAtlas atlas, TextureFilter typeOfFilter) { Gdx.app.log(TAG, "setting filter for textures " + atlas.getTextures().size); for (final Texture t : atlas.getTextures()) { t.setFilter(typeOfFilter, typeOfFilter); // min=mag } final Skin skin = assetsManager.get(skinPath, Skin.class); final BitmapFont font = skin.getFont("default-font"); for (int i = 0; i < font.getRegions().size; i++) { font.getRegion(i).getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); } }