Java源码示例:com.badlogic.gdx.graphics.g2d.NinePatch
示例1
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
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
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));
}
示例4
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;
}
示例5
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);
}
示例6
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);
}
示例7
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);
}
示例8
/**
*
* @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));
}
示例9
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);
}
示例10
@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);
}
示例11
public void setRegion (TextureRegion region, int[] splits) {
if(this.region != region) {
ninePatch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]);
}
this.region = region;
}
示例12
public void resetPatch (int[] splits) {
if(region == null) return;
ninePatch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]);
}
示例13
@Override
public void setPatch(NinePatch patch) {
patches.clear();
patches.add(patch);
super.setPatch(patch);
}
示例14
public void setPatches(Array<NinePatch> patches) {
this.patches.clear();
this.patches.addAll(patches);
}
示例15
public TImage(NinePatch patch) {
super(patch);
init();
}
示例16
private void updatePreviewNinePatch() {
int[] patches = model.readPatchValues();
NinePatch ninePatch = new NinePatch(model.texture, patches[0], patches[1], patches[2], patches[3]);
previewImage.setDrawable(new NinePatchDrawable(ninePatch));
}
示例17
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例18
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例19
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例20
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例21
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例22
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例23
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例24
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例25
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例26
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例27
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例28
public NinePatch getPatchBox () {
return patchBox;
}
示例29
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}
示例30
public PlatformAssets(TextureAtlas atlas) {
AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE);
int edge = Constants.PLATFORM_EDGE;
platformNinePatch = new NinePatch(region, edge, edge, edge, edge);
}