當前位置: 首頁>>代碼示例>>Java>>正文


Java NinePatch類代碼示例

本文整理匯總了Java中com.badlogic.gdx.graphics.g2d.NinePatch的典型用法代碼示例。如果您正苦於以下問題:Java NinePatch類的具體用法?Java NinePatch怎麽用?Java NinePatch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NinePatch類屬於com.badlogic.gdx.graphics.g2d包,在下文中一共展示了NinePatch類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadSkin

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
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;
}
 
開發者ID:LonamiWebs,項目名稱:Klooni1010,代碼行數:26,代碼來源:SkinLoader.java

示例2: findDrawable

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
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);
    }
 
開發者ID:varFamily,項目名稱:cocos-ui-libgdx,代碼行數:23,代碼來源:CocoStudioUIEditor.java

示例3: addWindowStyles

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
private void addWindowStyles() {
    final Color backgroundColor = new Color(0, 0.3f, 0.6f, 1f);
    final Color borderColor = new Color(backgroundColor).lerp(Color.WHITE, 0.2f);
    final int borderBorder = 4;
    final int borderWidth = 4;

    final int pixmapSize = 2 * (borderBorder + borderWidth) + 1;

    Pixmap windowBackground = new Pixmap(pixmapSize, pixmapSize, Pixmap.Format.RGBA8888);

    windowBackground.setColor(backgroundColor);
    windowBackground.fill();

    windowBackground.setColor(borderColor);
    windowBackground.fillRectangle(borderBorder, borderBorder, pixmapSize - 2 * borderBorder, pixmapSize - 2 * borderBorder);

    windowBackground.setColor(backgroundColor);
    windowBackground.fillRectangle(borderBorder + borderWidth, borderBorder + borderWidth, pixmapSize - 2 * (borderBorder + borderWidth), pixmapSize - 2 * (borderBorder + borderWidth));

    Texture backgroundWindow = new Texture(windowBackground);
    NinePatch backgroundPatch = new NinePatch(backgroundWindow, borderBorder + borderWidth, borderBorder + borderWidth, borderBorder + borderWidth, borderBorder + borderWidth);
    Drawable background = new NinePatchDrawable(backgroundPatch);
    BitmapFont font = get("normal", BitmapFont.class);
    WindowStyle window = new WindowStyle(font, Color.WHITE, background);
    add("default", window);
}
 
開發者ID:danirod,項目名稱:rectball,代碼行數:27,代碼來源:RectballSkin.java

示例4: Button

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
public Button(String text, float x, float y, int key) {
	font = new BitmapFont();
	layout = new GlyphLayout();

	this.key = key;
	this.text = text;
	setX(x);
	setY(y);

	layout.setText(font, text);

	setWidth((2 * offset) + layout.width);
	setHeight(11 + (2 * offset));

	np = new NinePatch(new Texture(Gdx.files.internal("gfx/ui/np.png")), 16, 16, 16, 16);
	np_hover = new NinePatch(new Texture(Gdx.files.internal("gfx/ui/np_hover.png")), 16, 16, 16, 16);
	np_checked = new NinePatch(new Texture(Gdx.files.internal("gfx/ui/np_checked.png")), 16, 16, 16, 16);
	np_checked_hover = new NinePatch(new Texture(Gdx.files.internal("gfx/ui/np_checked_hover.png")), 16, 16, 16,
			16);

	checkbox = false;
	checked = false;
}
 
開發者ID:ahmetkasif,項目名稱:KittenMaxit,代碼行數:24,代碼來源:Button.java

示例5: TilePanel

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
public TilePanel( Skin skin, Stage stage, Sprite tileBackground, Sprite tileBorder, int viewWidth, int viewHeight, int tileSize, boolean expandVertically )
{
	this.skin = skin;
	this.stage = stage;
	this.tileBackground = tileBackground;
	this.tileBorder = tileBorder;
	this.targetWidth = viewWidth;
	this.targetHeight = viewHeight;
	this.viewWidth = viewWidth;
	this.viewHeight = viewHeight;
	this.tileSize = tileSize;
	this.expandVertically = expandVertically;

	this.tilePanelBackgroundH = new NinePatch( AssetManager.loadTextureRegion( "Sprites/GUI/PanelHorizontal.png" ), 21, 21, 21, 21 );
	this.tilePanelBackgroundV = new NinePatch( AssetManager.loadTextureRegion( "Sprites/GUI/PanelVertical.png" ), 21, 21, 21, 21 );

	TilePanelListener listener = new TilePanelListener();

	this.addListener( listener );
	this.setWidth( getPrefWidth() );
}
 
開發者ID:infinity8,項目名稱:Roguelike,代碼行數:22,代碼來源:TilePanel.java

示例6: newMidlessPatch

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
static NinePatch newMidlessPatch () {
	final int patchSize = 8;
	final int fullPatchHeight = patchSize * 2;
	final int fullPatchWidth = patchSize * 3;
	final int pixmapDim = MathUtils.nextPowerOfTwo(Math.max(fullPatchWidth, fullPatchHeight));

	Pixmap testPatch = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888);
	testPatch.setColor(1, 1, 1, 0);
	testPatch.fill();

	for (int x = 0; x < fullPatchWidth; x += patchSize) {
		for (int y = 0; y < fullPatchHeight; y += patchSize) {
			testPatch.setColor(x / (float)fullPatchWidth, y / (float)fullPatchHeight, 1.0f, 1.0f);
			testPatch.fillRectangle(x, y, patchSize, patchSize);
		}
	}

	return new NinePatch(new TextureRegion(new Texture(testPatch), fullPatchWidth, fullPatchHeight), patchSize, patchSize,
		patchSize, patchSize);
}
 
開發者ID:basherone,項目名稱:libgdxcn,代碼行數:21,代碼來源:NinePatchTest.java

示例7: AudioControl

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
public AudioControl(TextureAtlas hudAtlas) {
	super(new NinePatchDrawable(new NinePatch(hudAtlas.findRegion("audio-on"), WHITE)), new NinePatchDrawable(new NinePatch(
			hudAtlas.findRegion("audio-on"), ICS_BLUE)), new NinePatchDrawable(new NinePatch(hudAtlas.findRegion("audio-off"), WHITE)));
	layout();

	GameSoundController.runAfterInit(new Runnable() {
		@Override
		public void run() {
			setChecked(!DroidTowersGame.getSoundController().isAudioState());

			addListener(new VibrateClickListener() {
				public void onClick(InputEvent event, float x, float y) {
					DroidTowersGame.getSoundController().toggleAudio();
				}
			});
		}
	});
}
 
開發者ID:frigidplanet,項目名稱:droidtowers,代碼行數:19,代碼來源:AudioControl.java

示例8: create

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
@Override
public void create() {
	float hh = Gdx.graphics.getHeight() / 2f, hw = Gdx.graphics.getWidth() / 2f;
	this.wBar = hw * 1.5f;
	this.hBar = hw / 7f;
	this.xBar = hw - this.wBar / 2f;
	this.yBar = hh / 2f - hBar / 2f;
	this.atlas = new TextureAtlas("data/ninepatch/ninepatch.atlas");
	this.loadingBar = new NinePatch(atlas.findRegion("2"), 4, 4, 4, 4);
	this.loadingProgress = new NinePatch(atlas.findRegion("3"), 4, 4, 4, 4);

	stage = new Stage(screenw,screenh, true);
	this.sb = stage.getSpriteBatch();	

	am = new AssetManager();
	/*-QUEUE here loading assets-*/
	am.load(SKIN_SRC, Skin.class);	
}
 
開發者ID:randombot,項目名稱:gametemplate,代碼行數:19,代碼來源:LoadManager.java

示例9: initMainMenu

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
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));
}
 
開發者ID:oddlydrawn,項目名稱:nahwc-g,代碼行數:23,代碼來源:Assets.java

示例10: get

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
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;
}
 
開發者ID:cobolfoo,項目名稱:gdx-skineditor,代碼行數:24,代碼來源:Skin.java

示例11: addTile

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
/**
 * Adds a tile to represent a ShipCoordinate.
 */
public void addTile( ShipCoordinate coord ) {
	if ( coord.v != 0 ) return;

	TextureAtlas floorAtlas = assetManager.get( OVDConstants.FLOORPLAN_ATLAS, TextureAtlas.class );

	TextureRegion tileRegion = floorAtlas.findRegion( "floor-line" );
	NinePatchDrawable tileDrawable = new NinePatchDrawable( new NinePatch( tileRegion, 1, 1, 1, 1 ) );
	Image tileImage = new Image( tileDrawable );
	tileImage.setPosition( calcTileX( coord ), calcTileY( coord ) );
	tileImage.setSize( tileSize, tileSize );
	tiles.add( tileImage );

	// These are different floats which can cause gaps when mixed.
	// (x * size + size) != ((x+1) * size)
}
 
開發者ID:Vhati,項目名稱:OverdriveGDX,代碼行數:19,代碼來源:ShipFloorLinesActor.java

示例12: addTile

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
/**
 * Adds a tile to represent a ShipCoordinate.
 */
public void addTile( ShipCoordinate coord ) {
	if ( coord.v != 0 ) return;

	TextureAtlas floorAtlas = assetManager.get( OVDConstants.FLOORPLAN_ATLAS, TextureAtlas.class );

	TextureRegion tileRegion = floorAtlas.findRegion( "floor-tile" );
	NinePatchDrawable tileDrawable = new NinePatchDrawable( new NinePatch( tileRegion, 1, 1, 1, 1 ) );
	Image tileImage = new Image( tileDrawable );
	tileImage.setPosition( calcTileX( coord ), calcTileY( coord ) );
	tileImage.setSize( tileSize, tileSize );
	this.addActor( tileImage );

	// These are different floats which can cause gaps when mixed.
	// (x * size + size) != ((x+1) * size)
}
 
開發者ID:Vhati,項目名稱:OverdriveGDX,代碼行數:19,代碼來源:ShipFloorTilesActor.java

示例13: textWindowDemo

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
private void textWindowDemo() {
	BitmapFont plotFont = context.getAssetManager().get( PLOT_FONT, BitmapFont.class );

	String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, ";
	loremIpsum += "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
	loremIpsum += "\n\nThis window is draggable.";

	rootAtlas = context.getAssetManager().get( ROOT_ATLAS, TextureAtlas.class );
	TextureRegion plotDlgRegion = rootAtlas.findRegion( "box-text1" );
	NinePatchDrawable plotDlgBgDrawable = new NinePatchDrawable( new NinePatch( plotDlgRegion, 20, 20, 35, 20 ) );

	Window plotDlg = new Window( "", new Window.WindowStyle( plotFont, new Color( 1f, 1f, 1f, 1f ), plotDlgBgDrawable ) );
	plotDlg.setKeepWithinStage( true );
	plotDlg.setMovable( true );
	plotDlg.setSize( 200, 250 );
	plotDlg.setPosition( 765, 60 );

	plotDlg.row().top().expand().fill();
	Label plotLbl = new Label( loremIpsum, new Label.LabelStyle( plotFont, new Color( 1f, 1f, 1f, 1f ) ) );
	plotLbl.setAlignment( Align.top|Align.left, Align.center|Align.left );
	plotLbl.setWrap( true );
	plotDlg.add( plotLbl );

	// setKeepWithinStage() only applies if added to the stage root. :/
	popupStage.addActor( plotDlg );
}
 
開發者ID:Vhati,項目名稱:OverdriveGDX,代碼行數:27,代碼來源:TestScreen.java

示例14: get

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
public <T> T get(String paramString, Class<T> paramClass)
{
  if (paramString == null)
    throw new IllegalArgumentException("name cannot be null.");
  if (paramClass == null)
    throw new IllegalArgumentException("type cannot be null.");
  Object localObject;
  if (paramClass == Drawable.class)
    localObject = getDrawable(paramString);
  do
  {
    return localObject;
    if (paramClass == TextureRegion.class)
      return getRegion(paramString);
    if (paramClass == NinePatch.class)
      return getPatch(paramString);
    if (paramClass == Sprite.class)
      return getSprite(paramString);
    ObjectMap localObjectMap = (ObjectMap)this.resources.get(paramClass);
    if (localObjectMap == null)
      throw new GdxRuntimeException("No " + paramClass.getName() + " registered with name: " + paramString);
    localObject = localObjectMap.get(paramString);
  }
  while (localObject != null);
  throw new GdxRuntimeException("No " + paramClass.getName() + " registered with name: " + paramString);
}
 
開發者ID:isnuryusuf,項目名稱:ingress-indonesia-dev,代碼行數:27,代碼來源:Skin.java

示例15: getSprite

import com.badlogic.gdx.graphics.g2d.NinePatch; //導入依賴的package包/類
public Sprite getSprite(String paramString)
{
  Object localObject = (Sprite)optional(paramString, Sprite.class);
  if (localObject != null)
    return localObject;
  try
  {
    TextureRegion localTextureRegion = getRegion(paramString);
    if ((localTextureRegion instanceof TextureAtlas.AtlasRegion))
    {
      TextureAtlas.AtlasRegion localAtlasRegion = (TextureAtlas.AtlasRegion)localTextureRegion;
      if ((localAtlasRegion.rotate) || (localAtlasRegion.packedWidth != localAtlasRegion.originalWidth) || (localAtlasRegion.packedHeight != localAtlasRegion.originalHeight))
        localObject = new TextureAtlas.AtlasSprite(localAtlasRegion);
    }
    if (localObject == null)
      localObject = new Sprite(localTextureRegion);
    add(paramString, localObject, NinePatch.class);
    return localObject;
  }
  catch (GdxRuntimeException localGdxRuntimeException)
  {
  }
  throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + paramString);
}
 
開發者ID:isnuryusuf,項目名稱:ingress-indonesia-dev,代碼行數:25,代碼來源:Skin.java


注:本文中的com.badlogic.gdx.graphics.g2d.NinePatch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。