Refine search
/** Calls {@link Page#updateTexture(TextureFilter, TextureFilter, boolean) updateTexture} for each page and adds a region to * the specified array for each page texture. */ public synchronized void updateTextureRegions (Array<TextureRegion> regions, TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { updatePageTextures(minFilter, magFilter, useMipMaps); while (regions.size < pages.size) regions.add(new TextureRegion(pages.get(regions.size).texture)); }
protected boolean isInsideRegion (TextureRegion region, float x, float y) { float rx = region.getRegionX(), ry = region.getRegionY(); return rx <= x && x <= rx +region.getRegionWidth() && ry <= y && y <= ry +region.getRegionHeight(); }
public void draw (Batch spriteBatch) { Array<TextureRegion> regions = font.getRegions(); for (int j = 0, n = pageVertices.length; j < n; j++) { if (idx[j] > 0) { // ignore if this texture has no glyphs float[] vertices = pageVertices[j]; spriteBatch.draw(regions.get(j).getTexture(), vertices, 0, idx[j]); } } }
/** Sets the texture to that of the specified region and sets the coordinates relative to the specified region. */ public void setRegion (TextureRegion region, int x, int y, int width, int height) { texture = region.texture; setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height); }
public void set (TextureRegion region) { this.u = region.getU(); this.v = region.getV(); this.u2 = region.getU2(); this.v2 = region.getV2(); this.halfInvAspectRatio = 0.5f * ((float)region.getRegionHeight() / region.getRegionWidth()); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/walkanim.png")); TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0]; Array<TextureRegion> rightWalkFrames = new Array(TextureRegion.class); for (int i = 0; i < leftWalkFrames.length; i++) { TextureRegion frame = new TextureRegion(leftWalkFrames[i]); frame.flip(true, false); rightWalkFrames.add(frame); } leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames); rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames); TextureRegion[] rightRegions = rightWalk.getKeyFrames(); // testing backing array type TextureRegion firstRightRegion = rightRegions[0]; Gdx.app.log("AnimationTest", "First right walk region is " + firstRightRegion.getRegionWidth() + "x" + firstRightRegion.getRegionHeight()); cavemen = new Caveman[100]; for (int i = 0; i < 100; i++) { cavemen[i] = new Caveman((float)Math.random() * Gdx.graphics.getWidth(), (float)Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false); } batch = new SpriteBatch(); fpsLog = new FPSLogger(); }
@Override public BitmapFont loadSync (AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) { if (parameter != null && parameter.atlasName != null) { TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class); String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString(); AtlasRegion region = atlas.findRegion(name); if (region == null) throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName); return new BitmapFont(file, region); } else { int n = data.getImagePaths().length; Array<TextureRegion> regs = new Array(n); for (int i = 0; i < n; i++) { regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class))); } return new BitmapFont(data, regs, true); } }
@Override public void renderImageLayer (TiledMapImageLayer layer) { final Color batchColor = batch.getColor(); final float color = Color.toFloatBits(batchColor.r, batchColor.g, final float x1 = x * unitScale; final float y1 = y * unitScale; final float x2 = x1 + region.getRegionWidth() * unitScale; final float y2 = y1 + region.getRegionHeight() * unitScale; final float u1 = region.getU(); final float v1 = region.getV2(); final float u2 = region.getU2(); final float v2 = region.getV(); vertices[V4] = v1; batch.draw(region.getTexture(), vertices, 0, NUM_VERTICES);
protected Array<TextureRegion> getRegions (Texture texture, Array<AtlasRegion> atlasRegions, Array<TextureRegion> out) { out.clear(); for(TextureRegion region : atlasRegions){ if(region.getTexture() == texture) out.add(region); } return out; }
public void draw (Batch batch, float x, float y, float width, float height) { Color batchColor = batch.getColor(); temp.set(batchColor); batch.setColor(batchColor.mul(color)); float regionWidth = region.getRegionWidth(), regionHeight = region.getRegionHeight(); int fullX = (int)(width / regionWidth), fullY = (int)(height / regionHeight); float remainingX = width - regionWidth * fullX, remainingY = height - regionHeight * fullY; Texture texture = region.getTexture(); float u = region.getU(); float v2 = region.getV2(); if (remainingX > 0) { float u2 = u + remainingX / texture.getWidth(); float v = region.getV(); y = startY; for (int ii = 0; ii < fullY; ii++) { v = v2 - remainingY / texture.getHeight(); batch.draw(texture, x, y, remainingX, remainingY, u, v2, u2, v); float u2 = region.getU2(); float v = v2 - remainingY / texture.getHeight(); x = startX; for (int i = 0; i < fullX; i++) {
@Override public void create () { ObjLoader objLoader = new ObjLoader(); sphere = objLoader.loadModel(Gdx.files.internal("data/sphere.obj")); sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)); cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.far = 200; Random rand = new Random(); for (int i = 0; i < instances.length; i++) { instances[i] = new ModelInstance(sphere, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3); } batch = new SpriteBatch(); font = new BitmapFont(); logo = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg"))); modelBatch = new ModelBatch(); }
/** Disposes the texture used by this BitmapFont's region IF this BitmapFont created the texture. */ public void dispose () { if (ownsTexture) { for (int i = 0; i < regions.size; i++) regions.get(i).getTexture().dispose(); } }
@Override public void onRegionsSelected (Array<TextureRegion> regions) { regionSelectDialog.setVisible(false); if(regions.size == 0) return; value.clear(); value.add((TextureRegion[])regions.toArray(TextureRegion.class)); editor.setTexture(regions.get(0).getTexture()); editor.restart(); }
public void draw(PolygonSpriteBatch batch) { if(dirty) { buildVertices(); } for(int i = 0; i < vertices.size; i++) { batch.draw(region.getTexture(), vertices.get(i), 0, vertices.get(i).length, indices.get(i), 0, indices.get(i).length); } }
/** Creates a decal assuming the dimensions of the texture region and adding transparency * * @param textureRegion Texture region to use * @param hasTransparency Whether or not this sprite will be treated as having transparency (transparent png, etc.) * @return Created decal */ public static Decal newDecal (TextureRegion textureRegion, boolean hasTransparency) { return newDecal(textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), textureRegion, hasTransparency ? GL20.GL_SRC_ALPHA : DecalMaterial.NO_BLEND, hasTransparency ? GL20.GL_ONE_MINUS_SRC_ALPHA : DecalMaterial.NO_BLEND); }
@Override public void create () { Texture texture = new Texture(Gdx.files.internal("data/layers.png")); layers = new TextureRegion[3]; layers[0] = new TextureRegion(texture, 0, 0, 542, 363); layers[1] = new TextureRegion(texture, 0, 363, 1024, 149); layers[2] = new TextureRegion(texture, 547, 0, 224, 51); camera = new ParallaxCamera(480, 320); controller = new OrthoCamController(camera); Gdx.input.setInputProcessor(controller); batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
@Override public void create () { camera = new OrthographicCamera(); spriteBatch = new SpriteBatch(); descriptionFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true); descriptionFont.setColor(Color.RED); regularTexture = new Texture(Gdx.files.internal("data/verdana39.png"), true); regularFont = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), new TextureRegion(regularTexture), true); regularFont.setColor(COLOR); distanceFieldTexture = new Texture(Gdx.files.internal("data/verdana39distancefield.png"), true); distanceFieldFont = new BitmapFont(Gdx.files.internal("data/verdana39distancefield.fnt"), new TextureRegion( distanceFieldTexture), true); distanceFieldFont.setColor(COLOR); distanceFieldShader = new DistanceFieldShader(); ShaderProgram.pedantic = false; // Useful when debugging this test }
/** Creates a BitmapFont from a BMFont file, using the specified image for glyphs. Any image specified in the BMFont file is * ignored. * @param flip If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. * @param integer If true, rendering positions will be at integer values to avoid filtering artifacts. */ public BitmapFont (FileHandle fontFile, FileHandle imageFile, boolean flip, boolean integer) { this(new BitmapFontData(fontFile, flip), new TextureRegion(new Texture(imageFile, false)), integer); ownsTexture = true; }
@Override public void create () { // a bitmap font to draw some text, note that we // pass true to the constructor, which flips glyphs on y font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true); // a texture region, note the flipping on y again region = new TextureRegion(new Texture("data/badlogic.jpg")); region.flip(false, true); // a texture atlas, note the boolean atlas = new TextureAtlas(Gdx.files.internal("data/pack"), true); // a sprite, created from a region in the atlas sprite = atlas.createSprite("badlogicsmall"); sprite.setPosition(0, 0); // a sprite batch with which we want to render batch = new SpriteBatch(); // a camera, note the setToOrtho call, which will set the y-axis // to point downwards camera = new OrthographicCamera(); camera.setToOrtho(true); // a stage which uses our y-down camera and a simple actor (see MyActor below), // which uses the flipped region. The key here is to // set our y-down camera on the stage, the rest is just for demo purposes. stage = new Stage(); stage.getViewport().setCamera(camera); image = new MyActor(region); image.setPosition(100, 100); stage.addActor(image); // finally we write up the stage as the input process and call it a day. Gdx.input.setInputProcessor(stage); }