Java Code Examples for com.badlogic.gdx.graphics.Texture#getWidth()
The following examples show how to use
com.badlogic.gdx.graphics.Texture#getWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLTFBinaryExporter.java From gdx-gltf with Apache License 2.0 | 6 votes |
public void export(GLTFImage image, Texture texture, String baseName) { String fileName = baseName + ".png"; image.uri = fileName; FileHandle file = folder.child(fileName); FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false); fbo.begin(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); SpriteBatch batch = new SpriteBatch(); batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1); batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); batch.begin(); batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight()); fbo.end(); batch.dispose(); fbo.dispose(); savePNG(file, pixmap); pixmap.dispose(); }
Example 2
Source File: AddViewSystem.java From Entitas-Java with MIT License | 6 votes |
@Override public void execute(List<GameEntity> entities) { for (GameEntity e : entities) { Texture texture = assetsManager.getTexture(String.format("assets/textures/%1$s.png", e.getAsset().name)); Body body = bodyBuilder.fixture(new FixtureDefBuilder() .boxShape(0.5f, 0.5f)) .type(BodyDef.BodyType.KinematicBody) .build(); TextureRegion textureRegion = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()); e.addTextureView(e.getAsset().name, textureRegion, body); // gameObject.Link(e, _pool); // if (e.hasPosition()) { Position pos = e.getPosition(); body.setTransform(new Vector2(pos.x, pos.y + 1), 0); } } }
Example 3
Source File: LR2SkinCSVLoader.java From beatoraja with GNU General Public License v3.0 | 6 votes |
protected TextureRegion[] getSourceImage(Texture image, int x, int y, int w, int h, int divx, int divy) { if (w == -1) { w = image.getWidth(); } if (h == -1) { h = image.getHeight(); } if (divx <= 0) { divx = 1; } if (divy <= 0) { divy = 1; } TextureRegion[] images = new TextureRegion[divx * divy]; for (int i = 0; i < divx; i++) { for (int j = 0; j < divy; j++) { images[divx * j + i] = new TextureRegion(image, x + w / divx * i, y + h / divy * j, w / divx, h / divy); } } return images; }
Example 4
Source File: JSONSkinLoader.java From beatoraja with GNU General Public License v3.0 | 6 votes |
protected TextureRegion[] getSourceImage(Texture image, int x, int y, int w, int h, int divx, int divy) { if (w == -1) { w = image.getWidth(); } if (h == -1) { h = image.getHeight(); } if (divx <= 0) { divx = 1; } if (divy <= 0) { divy = 1; } TextureRegion[] images = new TextureRegion[divx * divy]; for (int i = 0; i < divx; i++) { for (int j = 0; j < divy; j++) { images[divx * j + i] = new TextureRegion(image, x + w / divx * i, y + h / divy * j, w / divx, h / divy); } } return images; }
Example 5
Source File: UdacityScreen.java From ud405 with MIT License | 5 votes |
@Override public void show() { batch = new SpriteBatch(); logo = new Texture("udacity_logo_white.png"); logoHeight = logo.getHeight() * LOGO_WIDTH / logo.getWidth(); ParticleEffect touchEffect = new ParticleEffect(); touchEffect.load(Gdx.files.internal("UdacityEmitter.p"), Gdx.files.internal("")); touchEffect.setEmittersCleanUpBlendFunction(false); touchEffectPool = new ParticleEffectPool(touchEffect, 1, 2); Gdx.input.setInputProcessor(this); }
Example 6
Source File: ColorFadeTransition.java From libgdx-transitions with Apache License 2.0 | 5 votes |
@Override public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) { float width = currentScreenTexture.getWidth(); float height = currentScreenTexture.getHeight(); float x = 0; float y = 0; if (interpolation != null) percent = interpolation.apply(percent); batch.begin(); float fade = percent * 2; if (fade > 1.0f) { fade = 1.0f - (percent * 2 - 1.0f); color.a = 1.0f - fade; batch.setColor(color); batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true); } else { color.a = 1.0f - fade; batch.setColor(color); batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true); } color.a = fade; batch.setColor(color); batch.draw(texture, 0, 0, width, height); batch.end(); batch.setColor(Color.WHITE); }
Example 7
Source File: SlidingTransition.java From libgdx-transitions with Apache License 2.0 | 5 votes |
@Override public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) { float width = currentScreenTexture.getWidth(); float height = currentScreenTexture.getHeight(); float x = 0; float y = 0; if (interpolation != null) percent = interpolation.apply(percent); switch (direction) { case LEFT: x = -width * percent; if (!slideOut) x += width; break; case RIGHT: x = width * percent; if (!slideOut) x -= width; break; case UP: y = height * percent; if (!slideOut) y -= height; break; case DOWN: y = -height * percent; if (!slideOut) y += height; break; } Texture texBottom = slideOut ? nextScreenTexture : currentScreenTexture; Texture texTop = slideOut ? currentScreenTexture : nextScreenTexture; batch.begin(); batch.draw(texBottom, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true); batch.draw(texTop, x, y, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true); batch.end(); }
Example 8
Source File: SlicingTransition.java From libgdx-transitions with Apache License 2.0 | 5 votes |
@Override public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) { float width = currentScreenTexture.getWidth(); float height = currentScreenTexture.getHeight(); float x = 0; float y = 0; int sliceWidth = (int)(width / slices.size); batch.begin(); batch.draw(currentScreenTexture, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true); if (interpolation != null) percent = interpolation.apply(percent); for (int i = 0; i < slices.size; i++) { x = i * sliceWidth; float offsetY = height * (1 + slices.get(i) / (float)slices.size); switch (direction) { case UP: y = -offsetY + offsetY * percent; break; case DOWN: y = offsetY - offsetY * percent; break; case UPDOWN: if (i % 2 == 0) { y = -offsetY + offsetY * percent; } else { y = offsetY - offsetY * percent; } break; } batch.draw(nextScreenTexture, x, y, 0, 0, sliceWidth, nextScreenTexture.getHeight(), 1, 1, 0, i * sliceWidth, 0, sliceWidth, nextScreenTexture.getHeight(), false, true); } batch.end(); }
Example 9
Source File: RotatingTransition.java From libgdx-transitions with Apache License 2.0 | 5 votes |
@Override public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) { float width = currentScreenTexture.getWidth(); float height = currentScreenTexture.getHeight(); float x = 0; float y = 0; float scalefactor; switch (scaling) { case IN: scalefactor = percent; break; case OUT: scalefactor = 1.0f - percent; break; case NONE: default: scalefactor = 1.0f; break; } float rotation = 1; if (interpolation != null) rotation = interpolation.apply(percent); batch.begin(); batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true); batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), scalefactor, scalefactor, rotation * angle, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true); batch.end(); }
Example 10
Source File: SpriteSheet.java From TerraLegion with MIT License | 5 votes |
public void load(Texture texture, int spriteWidth, int spriteHeight, int gapWidth, int gapHeight) { dispose(); this.texture = texture; this.spriteWidth = spriteWidth; this.spriteHeight = spriteHeight; this.gapWidth = gapWidth; this.gapHeight = gapHeight; final int width = texture.getWidth(); final int height = texture.getHeight(); rowCount = ((width - spriteWidth) / (spriteWidth + gapWidth)) + 1; columnCount = ((height - spriteHeight) / (spriteHeight + gapHeight)) + 1; if ((height - spriteHeight) % (spriteHeight + gapHeight) != 0) { columnCount++; } sprites = new TextureRegion[columnCount][rowCount]; mirrored = new TextureRegion[columnCount][rowCount]; for (int column = 0; column < columnCount; column++) { for (int row = 0; row < rowCount; row++) { sprites[column][row] = extractSprite(row, column); TextureRegion mirroredSprite = new TextureRegion(sprites[column][row]); mirroredSprite.flip(true, false); mirrored[column][row] = mirroredSprite; } } }
Example 11
Source File: ScrollingBackground.java From libgdx-2d-tutorial with MIT License | 5 votes |
public ScrollingBackground () { image = new Texture("stars_background.png"); y1 = 0; y2 = image.getHeight(); speed = 0; goalSpeed = DEFAULT_SPEED; imageScale = SpaceGame.WIDTH / image.getWidth(); speedFixed = true; }
Example 12
Source File: Art.java From uracer-kotd with Apache License 2.0 | 5 votes |
private static TextureRegion[][] split (String name, int width, int height, boolean flipX, boolean flipY, boolean mipMap) { Texture texture = newTexture(name, mipMap); int xSlices = texture.getWidth() / width; int ySlices = texture.getHeight() / height; TextureRegion[][] res = new TextureRegion[xSlices][ySlices]; for (int x = 0; x < xSlices; x++) { for (int y = 0; y < ySlices; y++) { res[x][y] = new TextureRegion(texture, x * width, y * height, width, height); res[x][y].flip(flipX, flipY); } } return res; }
Example 13
Source File: Magic.java From super-snake with MIT License | 5 votes |
public Magic(float x, float y, String image_url) { super(x, y, 40); image = new Texture(Gdx.files.internal(image_url)); batch = new SpriteBatch(); srcWidth = image.getWidth(); srcHeight = image.getHeight(); float ratio = (float) srcHeight / (float) srcWidth; drawn_width = size; drawn_height = size * ratio; size = Math.max(size, size * ratio); }
Example 14
Source File: UdacityScreen.java From ud406 with MIT License | 5 votes |
@Override public void show() { batch = new SpriteBatch(); // TODO: Scavenger hunt! Where does this logo live? logo = new Texture("udacity_logo_white.png"); logoHeight = logo.getHeight() * LOGO_WIDTH / logo.getWidth(); ParticleEffect touchEffect = new ParticleEffect(); // TODO: Same question. Where does UdacityEmitter.p live? How are we loading it? touchEffect.load(Gdx.files.internal("UdacityEmitter.p"), Gdx.files.internal("")); touchEffect.setEmittersCleanUpBlendFunction(false); touchEffectPool = new ParticleEffectPool(touchEffect, 1, 2); Gdx.input.setInputProcessor(this); }
Example 15
Source File: CommonKeywordIconsPatches.java From StSLib with MIT License | 5 votes |
@SpirePostfixPatch public static void patch(SpriteBatch sb, String word, float x, float y, AbstractCard ___card) { if (___card == null || !CommonKeywordIconsField.useIcons.get(___card)) { return; } Texture badge = null; if (word.equals(GameDictionary.INNATE.NAMES[0])) { badge = StSLib.BADGE_INNATE; } else if (word.equals(GameDictionary.ETHEREAL.NAMES[0])) { badge = StSLib.BADGE_ETHEREAL; } else if (word.equals(GameDictionary.RETAIN.NAMES[0])) { badge = StSLib.BADGE_RETAIN; } else if (word.equals(purgeName)) { badge = StSLib.BADGE_PURGE; } else if (word.equals(GameDictionary.EXHAUST.NAMES[0])) { badge = StSLib.BADGE_EXHAUST; } if(badge != null) { float badge_w = badge.getWidth(); float badge_h = badge.getHeight(); sb.draw(badge, x + ((320.0F - badge_w/2 - 8f) * Settings.scale), y + (-16.0F * Settings.scale), 0, 0, badge_w, badge_h, 0.5f * Settings.scale, 0.5f * Settings.scale, 0, 0, 0, (int)badge_w, (int)badge_h, false, false); } }
Example 16
Source File: Filtering.java From ud406 with MIT License | 4 votes |
private void renderTextureCentered(SpriteBatch batch, Texture texture, float x, float y, float scale) { float scaledWidth = texture.getWidth() * scale; float scaledHeight = texture.getHeight() * scale; batch.draw(texture, x - scaledWidth / 2, y - scaledHeight / 2, scaledWidth, scaledHeight); }
Example 17
Source File: CommonKeywordIconsPatches.java From StSLib with MIT License | 4 votes |
private static void drawBadge(SpriteBatch sb, AbstractCard card, Hitbox hb, Texture img, int offset) { float badge_w = img.getWidth(); float badge_h = img.getHeight(); sb.draw(img, hb.x + hb.width - (badge_w * Settings.scale) * 0.66f, hb.y + hb.height - (badge_h * Settings.scale) * 0.5f - ((offset * (badge_h * Settings.scale)*0.6f)), 0, 0, badge_w , badge_h , Settings.scale, Settings.scale, card.angle, 0, 0, (int)badge_w, (int)badge_h, false, false); }
Example 18
Source File: ShareChallenge.java From Klooni1010 with GNU General Public License v3.0 | 4 votes |
public boolean saveChallengeImage(final int score, final boolean timeMode) { final File saveAt = getShareImageFilePath(); if (!saveAt.getParentFile().isDirectory()) if (!saveAt.mkdirs()) return false; final FileHandle output = new FileHandle(saveAt); final Texture shareBase = new Texture(Gdx.files.internal("share.png")); final int width = shareBase.getWidth(); final int height = shareBase.getHeight(); final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false); frameBuffer.begin(); // Render the base share texture final SpriteBatch batch = new SpriteBatch(); final Matrix4 matrix = new Matrix4(); matrix.setToOrtho2D(0, 0, width, height); batch.setProjectionMatrix(matrix); Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(shareBase, 0, 0); // Render the achieved score final Label.LabelStyle style = new Label.LabelStyle(); style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt")); Label label = new Label("just scored " + score + " on", style); label.setColor(Color.BLACK); label.setPosition(40, 500); label.draw(batch, 1); label.setText("try to beat me if you can"); label.setPosition(40, 40); label.draw(batch, 1); if (timeMode) { Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png"); batch.setColor(Color.BLACK); batch.draw(timeModeTexture, 200, 340); } batch.end(); // Get the framebuffer pixels and write them to a local file final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true); final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888); BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length); PixmapIO.writePNG(output, pixmap); // Dispose everything pixmap.dispose(); shareBase.dispose(); batch.dispose(); frameBuffer.end(); return true; }
Example 19
Source File: CommonKeywordIconsPatches.java From StSLib with MIT License | 4 votes |
@SpireInsertPatch( locator = Locator.class, localvars = {"tip"} ) public static void patch(float x, float y, SpriteBatch sb, ArrayList<PowerTip> powerTips, PowerTip tip) { if(!workaroundSwitch) { return; } Texture badge = null; if (tip.header.equalsIgnoreCase(GameDictionary.INNATE.NAMES[0])) { badge = StSLib.BADGE_INNATE; } else if (tip.header.equalsIgnoreCase(GameDictionary.ETHEREAL.NAMES[0])) { badge = StSLib.BADGE_ETHEREAL; } else if (tip.header.equalsIgnoreCase(GameDictionary.RETAIN.NAMES[0])) { badge = StSLib.BADGE_RETAIN; } else if (tip.header.equalsIgnoreCase(purgeName)) { badge = StSLib.BADGE_PURGE; } else if (tip.header.equalsIgnoreCase(GameDictionary.EXHAUST.NAMES[0])) { badge = StSLib.BADGE_EXHAUST; } if(badge != null) { float badge_w = badge.getWidth(); float badge_h = badge.getHeight(); sb.draw(badge, x + ((320.0F - badge_w/2 - 8f) * Settings.scale), y + (-16.0F * Settings.scale), 0, 0, badge_w, badge_h, 0.5f * Settings.scale, 0.5f * Settings.scale, 0, 0, 0, (int)badge_w, (int)badge_h, false, false); } if(powerTips.get(powerTips.size() - 1).equals(tip)) { workaroundSwitch = false; } }
Example 20
Source File: TextureUtil.java From seventh with GNU General Public License v2.0 | 3 votes |
/** * Loads an image * * @param image * @return * @throws Exception */ public static TextureRegion loadImage(String image) { Texture texture = new Texture(Gdx.files.internal(image)); TextureRegion region = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()); region.flip(false, true); return region; }