当前位置: 首页>>代码示例>>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;未经允许,请勿转载。