private void createTexture () { Pixmap pixmap = new Pixmap(256, 256, Format.RGB565); boolean useRed = true; for (int y = 0; y < 256; y += 8) { for (int x = 0; x < 256; x += 8) { pixmap.setColor(useRed ? 1 : 0, 0, useRed ? 0 : 1, 1); pixmap.fillRectangle(x, y, 8, 8); useRed = !useRed; } useRed = !useRed; } texture = new Texture(pixmap, true); texture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear); }
static TextureRegion newPatchPix (int patchSize, int pixmapSize) { final int pixmapDim = MathUtils.nextPowerOfTwo(pixmapSize); Pixmap p = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888); p.setColor(1, 1, 1, 0); p.fill(); for (int x = 0; x < pixmapSize; x += patchSize) { for (int y = 0; y < pixmapSize; y += patchSize) { p.setColor(x / (float)pixmapSize, y / (float)pixmapSize, 1.0f, 1.0f); p.fillRectangle(x, y, patchSize, patchSize); } } return new TextureRegion(new Texture(p), pixmapSize, pixmapSize); }
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); }
// Initially, the mask should have an alpha of 1 Pixmap mask = new Pixmap(128, 128, Pixmap.Format.Alpha); // Cut a rectangle of alpha value 0 mask.setBlending(Pixmap.Blending.None); mask.setColor(new Color(0f, 0f, 0f, 0f)); mask.fillRectangle(0, 0, 32, 32); Pixmap fg = new Pixmap(Gdx.files.internal("foreground.png")); fg.drawPixmap(mask, fg.getWidth(), fg.getHeight()); mask.setBlending(Pixmap.Blending.SourceOver); Texture foreground = new Texture(fg); Texture background = new Texture("background.png");
private Image getHealthIndicatorImage() { Image indicatorImage = new Image(); Pixmap healthIndicator = new Pixmap(AssetLoader.healthIndicatorV); Pixmap healthLevel = new Pixmap(healthIndicator.getWidth(), healthIndicator.getHeight(), Format.RGBA8888); healthLevel.setColor(Config.InstrumentPanel.healthInstrumentColor1); healthLevel.fillRectangle(0, 0, 50, 50); healthLevel.drawPixmap(healthIndicator, 0, 0); indicatorImage.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(healthLevel)))); indicatorImage.setScaling(Scaling.fit); return indicatorImage; }
private void drawMeter () { pixels.setColor(0.25f, 0.25f, 0.25f, color.a); pixels.fill(); float range = maxValue - minValue; float ratio = Math.abs(value) / range; ratio = AMath.clamp(ratio, 0, 1); pixels.setColor(color); pixels.fillRectangle(1, 1, (int)(width * ratio) - 2, height - 2); texture.draw(pixels, 0, 0); } }
private static void createTexture () { Pixmap pixmap = new Pixmap(3, 3, Pixmap.Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fillRectangle(0, 0, 3, 3); texture = new Texture(pixmap); pixmap.dispose(); }
private static Texture makePixel() { Texture _temp; Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888); p.setColor(Color.WHITE); p.fillRectangle(0, 0, 1, 1); _temp = new Texture(p, true); p.dispose(); return _temp; }
&& colorInt[2] == colorBlade) { pixmap.setColor(tintBlade); pixmap.fillRectangle(x, y, 1, 1); } else if (colorInt[0] == colorEdge && colorInt[1] == colorEdge && colorInt[2] == colorEdge) { pixmap.setColor(tintEdge); pixmap.fillRectangle(x, y, 1, 1); } else if (colorInt[0] == colorAffinity && colorInt[1] == colorAffinity && colorInt[2] == colorAffinity) { pixmap.setColor(tintAffinity); pixmap.fillRectangle(x, y, 1, 1); } else if (colorInt[0] == colorGrip && colorInt[1] == colorGrip && colorInt[2] == colorGrip) { pixmap.setColor(tintGrip); pixmap.fillRectangle(x, y, 1, 1); pixmap.fillRectangle(x, y, 1, 1);
public void clear() { Pixmap pixmap = getPixmap(); pixmap.setColor(0, 0, 0, 0); pixmap.fillRectangle(0, 0, pixmap.getWidth(), pixmap.getHeight()); updateTexture(); }
public Pixmap getCircleRectPixmap(int width, int height, int radius, Color color) { Pixmap pixmap = new Pixmap(width + radius * 2 + 1, height + radius * 2 + 1, Format.RGBA8888); pixmap.setFilter(Filter.BiLinear); // 绘制矩形 pixmap.setColor(color); pixmap.fillRectangle(0, radius, pixmap.getWidth(), height); pixmap.fillRectangle(radius, 0, width, pixmap.getHeight()); // 绘制4个圆角 pixmap.fillCircle(radius, radius, radius); pixmap.fillCircle(width + radius, radius, radius); pixmap.fillCircle(width + radius, height + radius, radius); pixmap.fillCircle(radius, height + radius, radius); return pixmap; }
/** * Returns a filled rectangular texture for the provided {@link Color} * * @param color * The {@link Color} to fetch a texture of * @return A new {@link Texture} if this is first time it has been * requested, otherwise it will return a cached instance of the * {@link Texture} for the given {@link Color} */ public Texture getFilledRectangleTexture(Color color) { int bits = color.toIntBits(); if (!filledRectangleTextures.containsKey(bits)) { Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pixmap.setColor(color); pixmap.fillRectangle(0, 0, 1, 1); filledRectangleTextures.put(bits, new Texture(pixmap)); pixmap.dispose(); } return filledRectangleTextures.get(bits); } }
_pixmap.fillRectangle(0, 0, _width, _height); _pixmapTexture = new Texture(_pixmap, Format.RGB888, false);