com.badlogic.gdx.graphics.g2d.NinePatch Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.NinePatch. 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: Skin.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
public <T> T get(String name, Class<T> type) {
	if (name == null)
		throw new IllegalArgumentException("name cannot be null.");
	if (type == null)
		throw new IllegalArgumentException("type cannot be null.");

	if (type == Drawable.class)
		return (T) getDrawable(name);
	if (type == TextureRegion.class)
		return (T) getRegion(name);
	if (type == NinePatch.class)
		return (T) getPatch(name);
	if (type == Sprite.class)
		return (T) getSprite(name);

	ObjectMap<String, Object> typeResources = resources.get(type);
	if (typeResources == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	Object resource = typeResources.get(name);
	if (resource == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	return (T) resource;
}
 
Example #2
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 #3
Source File: SkinLoader.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
static Skin loadSkin() {
    String folder = "ui/x" + bestMultiplier + "/";

    // Base skin
    Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));

    // Nine patches
    final int border = (int) (28 * bestMultiplier);
    skin.add("button_up", new NinePatch(new Texture(
            Gdx.files.internal(folder + "button_up.png")), border, border, border, border));

    skin.add("button_down", new NinePatch(new Texture(
            Gdx.files.internal(folder + "button_down.png")), border, border, border, border));

    for (String id : ids) {
        skin.add(id + "_texture", new Texture(Gdx.files.internal(folder + id + ".png")));
    }

    folder = "font/x" + bestMultiplier + "/";
    skin.add("font", new BitmapFont(Gdx.files.internal(folder + "geosans-light64.fnt")));
    skin.add("font_small", new BitmapFont(Gdx.files.internal(folder + "geosans-light32.fnt")));
    skin.add("font_bonus", new BitmapFont(Gdx.files.internal(folder + "the-next-font.fnt")));

    return skin;
}
 
Example #4
Source File: Assets.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public void initMainMenu() {
	atlas = new TextureAtlas(Gdx.files.internal(TEXTURE_ATLAS_LOC));
	
	checked = atlas.findRegion(CHECKED_REGION_STRING);
	unchecked = atlas.findRegion(UNCHECKED_REGION_STRING);
	background = atlas.findRegion(BACKGROUN_REGION_STRING);
	knob = atlas.findRegion(KNOB_REGION_STRING);
	
	titleSprite = atlas.createSprite(TITLE_REGION_STRING);
	
	levelOnePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_ONE_REGION_STRING));
	levelTwoPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_TWO_REGION_STRING));
	levelThreePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_THREE_REGION_STRING));
	levelFourPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FOUR_REGION_STRING));
	levelFivePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FIVE_REGION_STRING));
	
	patchBox = new NinePatch(atlas.createPatch(PATCH_BOX_REGION_STRING));


	finePrint = new BitmapFont(Gdx.files.internal(FINE_PRINT));
	font = new BitmapFont(Gdx.files.internal(FONT_LOC));
}
 
Example #5
Source File: StatusUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void createDynamicHpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch hpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch hpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	hpBar = new Image(hpBarPatch);
	hpBarBackground = new Image(hpBarBackgroundPatch);

	hpBar.setWidth(BAR_WIDTH * tileWidthPixel);
	hpBarBackground.setWidth(BAR_WIDTH * tileWidthPixel);
}
 
Example #6
Source File: NinePatchDemo.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    // TODO: Load the platform texture (Look for the file in android/assets)
    platformTexture = new Texture("platform.png");

    // TODO: Initialize the NinePatch using the texture and the EDGE constant
    platformNinePatch = new NinePatch(platformTexture, EDGE, EDGE, EDGE, EDGE);
}
 
Example #7
Source File: Assets.java    From ud406 with MIT License 5 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {

            // TODO: Find the AtlasRegion holding the platform
            AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);

            // TODO: Turn that AtlasRegion into a NinePatch using the edge constant you defined
            int edge = Constants.PLATFORM_EDGE;
            platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
        }
 
Example #8
Source File: HPBar.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void createDynamicHpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch hpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch hpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	hpBarImage = new Image(hpBarPatch);
	hpBarBackgroundImage = new Image(hpBarBackgroundPatch);
}
 
Example #9
Source File: AnimatedNinePatchDrawable.java    From skin-composer with MIT License 5 votes vote down vote up
/**
 * 
 * @param patches the frames to be drawn
 * @param frameDuration the delay between frames in seconds.
 */
public AnimatedNinePatchDrawable(Array<NinePatch> patches, float frameDuration) {
    this.patches = new Array<>(patches);
    t = 0.0f;
    this.frameDuration = frameDuration;
    index = 0;
    super.setPatch(patches.get(0));
}
 
Example #10
Source File: StatusUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void createDynamicXpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch xpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch xpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	xpBarPatch.setColor(Color.BLACK);
	xpBar = new Image(xpBarPatch);
	xpBarBackground = new Image(xpBarBackgroundPatch);
}
 
Example #11
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #12
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #13
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #14
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #15
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #16
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #17
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #18
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #19
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #20
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #21
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #22
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #23
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #24
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #25
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #26
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #27
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #28
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
 
Example #29
Source File: NinePatchDrawable.java    From talos with Apache License 2.0 4 votes vote down vote up
public void resetPatch (int[] splits) {
    if(region == null) return;
    ninePatch =  new NinePatch(region, splits[0], splits[1], splits[2], splits[3]);
}
 
Example #30
Source File: Assets.java    From ud406 with MIT License 4 votes vote down vote up
public PlatformAssets(TextureAtlas atlas) {
    AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
    int edge = Constants.PLATFORM_EDGE;
    platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}