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

The following examples show how to use com.badlogic.gdx.graphics.g2d.TextureRegion#getRegionWidth() . 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: 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 3
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 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: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a tileset from an image
 * 
 * @param image
 * @param tileWidth
 * @param tileHeight
 * @param margin
 * @param spacing
 * @return
 */
public static TextureRegion[] toTileSet(TextureRegion image, int tileWidth, int tileHeight, int margin, int spacing) {
    int nextX = margin;
    int nextY = margin;
    
    List<TextureRegion> images = new ArrayList<TextureRegion>();
    while (nextY + tileHeight + margin <= image.getRegionHeight()) {
        TextureRegion tile = new TextureRegion(image, nextX, nextY, tileWidth, tileHeight);
        tile.flip(false, true);
        
        images.add(tile);
        
        nextX += tileWidth + spacing;

        if (nextX + tileWidth + margin > image.getRegionWidth()) {
            nextX = margin;
            nextY += tileHeight + spacing;
        }            
    }
    
    return images.toArray(new TextureRegion[images.size()]);
}
 
Example 6
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
public Drawable findDrawable(ObjectData option, String name) {

        if (option.isScale9Enable()) {// 九宫格支持
            TextureRegion textureRegion = findTextureRegion(option, name);
            NinePatch np = new NinePatch(textureRegion,
                option.getScale9OriginX(),
                textureRegion.getRegionWidth() - option.getScale9Width() - option.getScale9OriginX(),
                option.getScale9OriginY(),
                textureRegion.getRegionHeight() - option.getScale9Height() - option.getScale9OriginY());

            np.setColor(getColor(option.getCColor(), option.getAlpha()));
            return new NinePatchDrawable(np);
        }

        TextureRegion tr = findTextureRegion(option, name);

        if (tr == null) {
            return null;
        }

        return new TextureRegionDrawable(tr);
    }
 
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: 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 10
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 11
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 12
Source File: LayoutItem.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public LayoutItem(TextureRegion region) {
	this.region = region;
	originX = originY = 0;
	scaleX = scaleY = 1f;
	rotation = 0;
	width = region.getRegionWidth();
	height = region.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();

    // 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 14
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 15
Source File: LayoutItem.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public LayoutItem(TextureRegion region, float scale, float rotation) {
	this.region = region;
	originX = region.getRegionWidth()/2;
	originY = region.getRegionHeight()/2;
	scaleX = scaleY = scale;
	this.rotation = rotation;
	width = (int) (scale*region.getRegionWidth());
	height = (int) (scale*region.getRegionHeight());
}
 
Example 16
Source File: SkinTextImage.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void prepareText(String text) {
	byte[] b = null;
	try {
		b = text.getBytes("utf-16le");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
		return;
	}
	textwidth = 0;
	texts.clear();
	for (int i = 0; i < b.length;) {
		int code = 0;
		code |= (b[i++] & 0xff);
		code |= (b[i++] & 0xff) << 8;
		if (code >= 0xdc00 && code < 0xff00 && i < b.length) {
			code |= (b[i++] & 0xff) << 16;
			code |= (b[i++] & 0xff) << 24;
		}
		final TextureRegion ch = source.getImage(code);
		if (ch != null) {
			texts.add(ch);
			textwidth += ch.getRegionWidth();
		} else {
			// System.out.println(text + " -> " + Arrays.toString(b) +
			// "code not found : " + Integer.toHexString(code));
		}
	}
}
 
Example 17
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 18
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 19
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);
}
 
Example 20
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();
	}
}