本文整理匯總了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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() );
}
示例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);
}
示例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();
}
});
}
});
}
示例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);
}
示例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));
}
示例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;
}
示例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)
}
示例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)
}
示例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 );
}
示例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);
}
示例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);
}