Java Code Examples for com.badlogic.gdx.graphics.g2d.TextureRegion#getRegionHeight()

The following examples show how to use com.badlogic.gdx.graphics.g2d.TextureRegion#getRegionHeight() . 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: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 2
Source File: Box2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
public Box2dSteeringEntity createSteeringEntity (World world, TextureRegion region, boolean independentFacing, int posX, int posY) {

		CircleShape circleChape = new CircleShape();
		circleChape.setPosition(new Vector2());
		int radiusInPixels = (int)((region.getRegionWidth() + region.getRegionHeight()) / 4f);
		circleChape.setRadius(Box2dSteeringTest.pixelsToMeters(radiusInPixels));

		BodyDef characterBodyDef = new BodyDef();
		characterBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(posX), Box2dSteeringTest.pixelsToMeters(posY));
		characterBodyDef.type = BodyType.DynamicBody;
		Body characterBody = world.createBody(characterBodyDef);

		FixtureDef charFixtureDef = new FixtureDef();
		charFixtureDef.density = 1;
		charFixtureDef.shape = circleChape;
		charFixtureDef.filter.groupIndex = 0;
		characterBody.createFixture(charFixtureDef);

		circleChape.dispose();

		return new Box2dSteeringEntity(region, characterBody, independentFacing, Box2dSteeringTest.pixelsToMeters(radiusInPixels));
	}
 
Example 3
Source File: AnimationEditorScreen.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
private void renderAnimationWheel(Canvas canvas, TextureRegion activeFrame) {
        /* render the animation frames */
//        int center = canvas.getWidth()/2 - activeFrame.getRegionWidth()/2; 
        
        int x = 0;//center - activeFrame.getRegionWidth() * animation.getAnimation().getCurrentFrame();
        int y = ((canvas.getHeight()/3) + canvas.getHeight()/2) - activeFrame.getRegionHeight();
        TextureRegion[] frames = animation.getImages();
        
        for(TextureRegion frame : frames) {
            int frameColor = 0xff00ff00;
            if(activeFrame==frame) {
                frameColor = 0xffff00ff;
            }
            
            canvas.drawImage(frame, x, y, null);
            canvas.drawRect(x,y, frame.getRegionWidth(), frame.getRegionHeight(), frameColor);
            x+=frame.getRegionWidth();
        }
    }
 
Example 4
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 5
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 6
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 7
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 8
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 9
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 10
Source File: Utils.java    From skin-composer with MIT License 6 votes vote down vote up
public static Pixmap textureRegionToPixmap(TextureRegion textureRegion) {
    var texture = textureRegion.getTexture();
    if (!texture.getTextureData().isPrepared()) {
        texture.getTextureData().prepare();
    }
    
    var pixmap = texture.getTextureData().consumePixmap();
    var returnValue = new Pixmap(textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), Pixmap.Format.RGBA8888);
    returnValue.setBlending(Pixmap.Blending.None);
    
    for (int x = 0; x < textureRegion.getRegionWidth(); x++) {
        for (int y = 0; y < textureRegion.getRegionHeight(); y++) {
            int colorInt = pixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y);
            returnValue.drawPixel(x, y, colorInt);
        }
    }
    
    pixmap.dispose();
    
    return returnValue;
}
 
Example 11
Source File: SteeringActor.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
public SteeringActor (TextureRegion region, boolean independentFacing) {
	this.independentFacing = independentFacing;
	this.region = region;
	this.position = new Vector2();
	this.linearVelocity = new Vector2();
	this.setBounds(0, 0, region.getRegionWidth(), region.getRegionHeight());
	this.boundingRadius = (region.getRegionWidth() + region.getRegionHeight()) / 4f;
	this.setOrigin(region.getRegionWidth() * .5f, region.getRegionHeight() * .5f);
}
 
Example 12
Source File: RadialDrawable.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public void setTextureRegion(final TextureRegion textureRegion) {
    this.texture = textureRegion.getTexture();
    this.u1 = textureRegion.getU();
    this.v1 = textureRegion.getV();
    this.u2 = textureRegion.getU2();
    this.v2 = textureRegion.getV2();
    this.du = u2 - u1;
    this.dv = v2 - v1;
    this.width = textureRegion.getRegionWidth();
    this.height = textureRegion.getRegionHeight();
    this.dirty = true;

    setMinWidth(textureRegion.getRegionWidth());
    setMinHeight(textureRegion.getRegionHeight());
}
 
Example 13
Source File: GigaGalHud.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);

    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;

    for (int i = 1; i <= lives; i++) {

        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );

        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();

}
 
Example 14
Source File: ImageCursor.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param image 
 *             the cursor image to use
 */
public ImageCursor(TextureRegion image) {
    super(new Rectangle(image.getRegionWidth(), image.getRegionHeight()));
    this.cursorImg = image;
    
    int imageWidth = cursorImg.getRegionWidth();
    int imageHeight = cursorImg.getRegionHeight();
    this.imageOffset = new Vector2f(imageWidth/2, imageHeight/2);
}
 
Example 15
Source File: GigaGalHud.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();

    // TODO: Draw GigaGal's score and ammo count in the top left of the viewport
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);

    // TODO: Draw a tiny GigaGal in the top right for each life left
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }

    batch.end();
}
 
Example 16
Source File: Background.java    From Unlucky with MIT License 5 votes vote down vote up
/**
 * Fixes the slight 1 pixel offset when moving the background to create
 * a smooth cycling image
 *
 * @param region
 */
public void fixBleeding(TextureRegion region) {
    float fix = 0.01f;

    float x = region.getRegionX();
    float y = region.getRegionY();
    float width = region.getRegionWidth();
    float height = region.getRegionHeight();
    float invTexWidth = 1f / region.getTexture().getWidth();
    float invTexHeight = 1f / region.getTexture().getHeight();
    region.setRegion((x + fix) * invTexWidth, (y + fix) * invTexHeight, (x + width - fix) * invTexWidth, (y + height - fix) * invTexHeight);
}
 
Example 17
Source File: DebugAnimationEffect.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public void render(Canvas canvas, Camera camera, float a) {
            
        int rx = (int)(pos.x);
        int ry = (int)(pos.y);
        
        float alpha = 1.0f;
        if(!this.persist) {
             alpha = (float)this.fade.getCurrentValue() / 255.0f;
        }
        
        float priorAlpha = canvas.getCompositeAlpha();
        canvas.setCompositeAlpha(alpha);
        
        TextureRegion region = anim.getCurrentImage();
        sprite.setRegion(region);
                
        if(offsetX != 0 || offsetY != 0) {
            //sprite.setSize(16, 16);
            sprite.setPosition(rx-offsetX, ry-offsetY);
            //sprite.setPosition(rx+22, ry-43);
            sprite.setOrigin(offsetX, offsetY);
        }
        else {
            int w = region.getRegionWidth() / 2;
            int h = region.getRegionHeight() / 2;
            
            sprite.setPosition(rx-w, ry-h);
        }
        sprite.setRotation(this.rotation-90);
        
//        sprite.setColor(1, 1, 1, alpha);
        canvas.drawSprite(sprite);
        canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), 0xff00aa00);
        canvas.setCompositeAlpha(priorAlpha);
    }
 
Example 18
Source File: Background.java    From Unlucky with MIT License 5 votes vote down vote up
public Background(TextureRegion image, OrthographicCamera cam, Vector2 scale) {
    this.image = image;
    this.cam = cam;
    this.scale = scale;
    numDrawX = (Unlucky.V_WIDTH * 2) / image.getRegionWidth() + 1;
    numDrawY = (Unlucky.V_HEIGHT * 2) / image.getRegionHeight() + 1;

    fixBleeding(image);
}
 
Example 19
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void layout() {
	final BitmapFont font = style.font;
	final BitmapFont subfont = style.subtitleFont;
	final Drawable selectedDrawable = style.selection;

	cellRenderer.layout(style);

	GlyphLayout textLayout = new GlyphLayout();

	prefWidth = 0;
	for (int i = 0; i < items.size; i++) {

		textLayout.setText(font, cellRenderer.getCellTitle(items.get(i)));

		prefWidth = Math.max(textLayout.width, prefWidth);
		
		if (cellRenderer.hasImage()) {
			TextureRegion r = cellRenderer.getCellImage(items.get(i));

			float ih = r.getRegionHeight();
			float iw = r.getRegionWidth();

			if (ih > getItemHeight() - 10) {
				ih = getItemHeight() - 10;
				iw *= ih / r.getRegionHeight();
			}

			prefWidth = Math.max(iw + textLayout.width, prefWidth);
		}

		if (cellRenderer.hasSubtitle()) {
			String subtitle = cellRenderer.getCellSubTitle(items.get(i));

			if (subtitle != null) {
				textLayout.setText(subfont, subtitle);
				prefWidth = Math.max(textLayout.width, prefWidth);
			}
		}
	}
	
	prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();

	prefHeight = items.size * cellRenderer.getItemHeight();

	Drawable background = style.background;
	if (background != null) {
		prefWidth += background.getLeftWidth() + background.getRightWidth();
		prefHeight += background.getTopHeight() + background.getBottomHeight();
	}
}
 
Example 20
Source File: Background.java    From Unlucky with MIT License 4 votes vote down vote up
public void setImage(TextureRegion image) {
    this.image = image;
    numDrawX = (Unlucky.V_WIDTH * 2) / image.getRegionWidth() + 1;
    numDrawY = (Unlucky.V_HEIGHT * 2) / image.getRegionHeight() + 1;
    fixBleeding(image);
}