Java Code Examples for com.badlogic.gdx.graphics.Texture#getHeight()

The following examples show how to use com.badlogic.gdx.graphics.Texture#getHeight() . 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 vote down vote up
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 vote down vote up
@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 vote down vote up
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 vote down vote up
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 ud406 with MIT License 5 votes vote down vote up
@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 6
Source File: CommonKeywordIconsPatches.java    From StSLib with MIT License 5 votes vote down vote up
@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 7
Source File: UdacityScreen.java    From ud405 with MIT License 5 votes vote down vote up
@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 8
Source File: CreditsScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private float processCreditImage(SpriteBatch batch, int width, int height, float y, int i, String s) {
	Texture img = images.get(s);
	final int lineHeight = img.getHeight();
	batch.draw(img, (width - img.getWidth()) / 2, y - lineHeight);

	y -= lineHeight;

	if (y > height) {
		stringHead = i + 1;
		scrollY -= lineHeight;
	}
	return y;
}
 
Example 9
Source File: Vignetting.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
/** Sets the texture with which gradient mapping will be performed. */
public void setLut( Texture texture ) {
	texLut = texture;
	dolut = (texLut != null);

	if( dolut ) {
		lutStep = 1f / (float)texture.getHeight();
		lutStepOffset = lutStep / 2f; // center texel
		setParams( Param.TexLUT, u_texture1 );
		setParams( Param.LutStep, lutStep );
		setParams( Param.LutStepOffset, lutStepOffset ).endParams();
	}
}
 
Example 10
Source File: SlicingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: RotatingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: ScrollingBackground.java    From libgdx-2d-tutorial with MIT License 5 votes vote down vote up
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 13
Source File: Art.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
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 14
Source File: Vignetting.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** Sets the texture with which gradient mapping will be performed. */
public void setLut (Texture texture) {
	texLut = texture;
	dolut = (texLut != null);

	if (dolut) {
		lutStep = 1f / (float)texture.getHeight();
		lutStepOffset = lutStep / 2f; // center texel
		setParams(Param.TexLUT, u_texture1);
		setParams(Param.LutStep, lutStep);
		setParams(Param.LutStepOffset, lutStepOffset).endParams();
	}
}
 
Example 15
Source File: Magic.java    From super-snake with MIT License 5 votes vote down vote up
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 16
Source File: ShareChallenge.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
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 17
Source File: CommonKeywordIconsPatches.java    From StSLib with MIT License 4 votes vote down vote up
@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 18
Source File: Filtering.java    From ud406 with MIT License 4 votes vote down vote up
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 19
Source File: CommonKeywordIconsPatches.java    From StSLib with MIT License 4 votes vote down vote up
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 20
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
}