Java 类com.badlogic.gdx.graphics.Pixmap 实例源码

项目:ProjektGG    文件:ScreenshotUtils.java   
public static void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0,
            Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), true);

    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);

    SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyy-MM-dd HH-mm-ss");

    PixmapIO.writePNG(
            Gdx.files.external(dateFormat.format(new Date()) + ".png"),
            pixmap);
    pixmap.dispose();
}
项目:Cubes    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
  if (pages == null || pages.length == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

  String[] pageRefs = new String[pages.length];

  for (int i = 0; i < pages.length; i++) {
    String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

    // the ref for this image
    pageRefs[i] = ref;

    // write the PNG in that directory
    PixmapIO.writePNG(outputDir.child(ref), pages[i]);
  }
  return pageRefs;
}
项目:LD38-Compo    文件:LudumDare38.java   
private void createToolTip()
{
    Skin skin = new Skin();
    Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));
    skin.add("default", new BitmapFont());

    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", new Color(0, 0, 0, 1));
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    labelToolTip = new TextButton("TEST", skin);
    labelToolTip.setX(5);
    labelToolTip.setY(5);
    labelToolTip.setWidth(125);
    labelToolTip.setVisible(false);
    labelToolTip.getLabel().setWrap(true);
    labelToolTip.setHeight(labelToolTip.getLabel().getHeight());
    group.addActor(labelToolTip);
}
项目:LD38-Compo    文件:LudumDare38.java   
private void createResetButton()
{
    Skin skin = new Skin();
    Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));
    skin.add("default", new BitmapFont());

    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", new Color(0, 0, 0, 1));
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    btnReset = new TextButton("RESET", skin);
    btnReset.setX(5);
    btnReset.setY(Gdx.graphics.getHeight() - 25);
    btnReset.setWidth(60);
    btnReset.setVisible(true);
    group.addActor(btnReset);
}
项目:LD38-Compo    文件:LudumDare38.java   
private void createUndoButton()
{
    Skin skin = new Skin();
    Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));
    skin.add("default", new BitmapFont());

    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", new Color(0, 0, 0, 1));
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    btnUndo = new TextButton("UNDO", skin);
    btnUndo.setX(70);
    btnUndo.setY(Gdx.graphics.getHeight() - 25);
    btnUndo.setWidth(60);
    btnUndo.setVisible(true);
    group.addActor(btnUndo);
}
项目:LD38-Compo    文件:TileData.java   
public void setColor(int color) {
    Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pix.setColor(color);
    pix.fill();
    Texture tex = new Texture(pix);
    TextureRegion region = new TextureRegion(tex);

    Point p1 = (Point) parent.getPoints().toArray()[0];
    Point p2 = (Point) parent.getPoints().toArray()[1];
    Point p3 = (Point) parent.getPoints().toArray()[2];
    Point p4 = (Point) parent.getPoints().toArray()[3];
    Point p5 = (Point) parent.getPoints().toArray()[4];
    Point p6 = (Point) parent.getPoints().toArray()[5];

    float[] vertices = new float[]{(
            float) p1.getCoordinateX(), (float)p1.getCoordinateY(),
            (float)p2.getCoordinateX(), (float)p2.getCoordinateY(),
            (float)p3.getCoordinateX(), (float)p3.getCoordinateY(),
            (float) p4.getCoordinateX(), (float)p4.getCoordinateY(),
            (float)p5.getCoordinateX(), (float)p5.getCoordinateY(),
            (float)p6.getCoordinateX(), (float)p6.getCoordinateY()};
    EarClippingTriangulator triangulator = new EarClippingTriangulator();
    ShortArray triangleIndices = triangulator.computeTriangles(vertices);
    PolygonRegion polygonRegion = new PolygonRegion(region, vertices, triangleIndices.toArray());
    sprite = new PolygonSprite(polygonRegion);
}
项目:Cubes    文件:Graphics.java   
public static void takeScreenshot() {
  Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
  FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
  dir.mkdirs();
  FileHandle f = dir.child(System.currentTimeMillis() + ".png");
  try {
    PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
    try {
      writer.setFlipY(true);
      writer.write(f, pixmap);
    } finally {
      writer.dispose();
    }
  } catch (IOException ex) {
    throw new CubesException("Error writing PNG: " + f, ex);
  } finally {
    pixmap.dispose();
  }
  Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
项目:ggvm    文件:PatternTableManager.java   
/**
 * Initializes the pattern table textures and pixmap.
 */
public void initialize() {
    //Allocate a pixmap big enough to accommodate both pattern tables.
    patternTablePixmap = new Pixmap(128, 256, Pixmap.Format.RGBA8888);
    //Set blending to none so we can rewrite the pixmap and draw it to the
    //pattern table texture when graphics are regenerated.
    patternTablePixmap.setBlending(Pixmap.Blending.None);

    //Allocate a pixmap the size of one tile for live CHR-RAM updates.
    patternPixmap = new Pixmap(8, 8, Pixmap.Format.RGBA8888);
    patternPixmap.setBlending(Pixmap.Blending.None);

    patternTableTexture = new Texture(patternTablePixmap, false);
    TextureRegion[][] textureRegions = TextureRegion.split(patternTableTexture, 8, 8);
    patternTableSprites = new Sprite[32][16];
    for(int row = 0; row < 32; row++) {
        for(int column = 0; column < 16; column++) {
            TextureRegion textureRegion = textureRegions[row][column];
            patternTableSprites[row][column] = new Sprite(textureRegion);
        }
    }
    initializeMonochromePalette();
}
项目:Mindustry    文件:Maps.java   
public void saveAndReload(Map map, Pixmap out){
    if(map.pixmap != null && out != map.pixmap && map.texture != null){
        map.texture.dispose();
        map.texture = new Texture(out);
    }else if (out == map.pixmap){
        map.texture.draw(out, 0, 0);
    }

    map.pixmap = out;
    if(map.texture == null) map.texture = new Texture(map.pixmap);

    if(map.id == -1){
        if(mapNames.containsKey(map.name)){
            map.id = mapNames.get(map.name).id;
        }else{
            map.id = ++lastID;
        }
    }

    if(!Settings.has("hiscore" + map.name)){
        Settings.defaults("hiscore" + map.name, 0);
    }

    saveCustomMap(map);
    Vars.ui.levels.reload();
}
项目:Mindustry    文件:Maps.java   
private boolean loadMapFile(FileHandle file){
    try{
        Array<Map> arr = json.fromJson(ArrayContainer.class, file).maps;
        if(arr != null){ //can be an empty map file
            for(Map map : arr){
                map.pixmap = new Pixmap(file.sibling(map.name + ".png"));
                map.texture = new Texture(map.pixmap);
                maps.put(map.id, map);
                mapNames.put(map.name, map);
                lastID = Math.max(lastID, map.id);
            }
        }
        return true;
    }catch(Exception e){
        if(!Vars.android) e.printStackTrace();
        Gdx.app.error("Mindustry-Maps", "Failed loading map file: " + file);
        return false;
    }
}
项目:odb-little-fortune-planet    文件:PlanetStencilSystem.java   
private void stencil(Planet planet, Texture texture, PlanetCell.CellType[] replaceTypes, int degrees, int x1, int y1) {
    final TextureData textureData = texture.getTextureData();
    textureData.prepare();

    final Pixmap pixmap = textureData.consumePixmap();
    for (int y = 0; y < texture.getHeight(); y++) {
        for (int x = 0; x < texture.getWidth(); x++) {

            tv.set(x, y).rotate(degrees).add(x1, y1);

            int color = pixmap.getPixel(x, texture.getHeight() - y);
            final PlanetCell.CellType type = getSourceCellType(planet, color);
            if (type != null) {
                replaceCell(planet, Math.round(tv.x), Math.round(tv.y), replaceTypes, type, color);
            }

        }
    }
    pixmap.dispose();
}
项目:Climatar    文件:DrawableMap.java   
public void draw(Coordinates<Integer> coords, Pixmap map) {
    int terrainID = world.get(coords.y).get(coords.x);

    // tileID runs 0 through 8, conveniently in the
    // same order as our split tiles texture...
    int ty = (int) terrainID / 3;
    int tx = terrainID % 3;

    TextureRegion tileRegion = tileRegions[ty][tx];

    map.drawPixmap(tilesPixmap,
                   coords.x * tileSize,
                   coords.y * tileSize,
                   tileRegion.getRegionX(),
                   tileRegion.getRegionY(),
                   tileRegion.getRegionWidth(),
                   tileRegion.getRegionHeight());
}
项目:miniventure    文件:TileTouchCheck.java   
private TileTouchCheck(Pixmap pixelMap, TextureRegion region) {
    this.width = region.getRegionWidth();
    this.height = region.getRegionHeight();
    map = new int[width * height];
    int i = -1;
    // pixmap coordinates have the origin in the top left corner; shift it so it goes from the bottom left instead
    for (int x = 0; x < width; x++) {
        for (int y = height-1; y >= 0; y--) {
            Color color = new Color(pixelMap.getPixel(region.getRegionX() + x, region.getRegionY() + y));

            i++;
            if(color.a == 0) continue; // set to zero, tile doesn't matter

            if(color.equals(Color.WHITE)) // the tile must be different from the center tile
                map[i] = WHITE;
            else if(color.equals(Color.BLACK)) // the tile must be equal to the center tile
                map[i] = BLACK;
        }
    }
}
项目:TH902    文件:Player.java   
public PlayerAnimation() {
    nullRegion = new TextureRegion(new Texture(new Pixmap(1, 1, Pixmap.Format.RGBA8888)));
    for (int i = 0; i < regions.length; i++) {
        Pixmap pixmap = new Pixmap(64, 64, Pixmap.Format.RGBA8888);
        pixmap.setColor(0, 0, 1, 1);
        pixmap.fillCircle(32, 32, 10);
        pixmap.setColor(1, 1, 1, 1);
        pixmap.fillCircle(32, 32, 5);
        pixmap.setColor(1, 1, 1, 0.5f);
        pixmap.drawCircle(32, 32, (int) (i * 3f) + 7);
        pixmap.setColor(1, 1, 1, 1f);
        pixmap.drawCircle(32, 32, (int) (i * 3f) + 8);
        pixmap.setColor(1, 1, 1, 0.5f);
        pixmap.drawCircle(32, 32, (int) (i * 3f) + 9);
        regions[i] = new TextureRegion(new Texture(pixmap));
        pixmap.dispose();
    }
    setRegion(regions[0]);
}
项目:Tower-Defense-Galaxy    文件:VRCamera.java   
public VRCamera(int width, int height, int viewportWidth, int viewportHeight) {
    leftCamera = new PerspectiveCamera(90, viewportWidth, viewportHeight);
    rightCamera = new PerspectiveCamera(90, viewportWidth, viewportHeight);
    leftBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, true);
    rightBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, true);
    leftTexture = new TextureRegion();
    rightTexture = new TextureRegion();
    batch = new SpriteBatch();
    this.width = width;
    this.height = height;
    this.viewportWidth = viewportWidth;
    this.viewportHeight = viewportHeight;
    tmpVector3 = new Vector3();
    position = new Vector3(250, 20, 250);
    positionLeft = new Vector3(249.5f, 20, 250);
    positionRight = new Vector3(250.5f, 20, 250);
    direction = new Vector3();
    up = new Vector3(0, 1, 0);
    eyeDistance = 0.5f;
}
项目:Cubes_2    文件:AOTextureGenerator.java   
private static void setupPixmap(Pixmap p, int i, Color c) {
    p.setColor(c);

    setupPixMapA(i, p);

    if ((i & AmbientOcclusion.E) == AmbientOcclusion.E) {
        p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE,
                AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
    }

    if ((i & AmbientOcclusion.F) == AmbientOcclusion.F) {
        p.fillRectangle(0, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE,
                AmbientOcclusion.INDIVIDUAL_SIZE);
    }
    if ((i & AmbientOcclusion.G) == AmbientOcclusion.G) {
        p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE * 2,
                AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
    }
    if ((i & AmbientOcclusion.H) == AmbientOcclusion.H) {
        p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE * 2,
                AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
    }
}
项目:Cubes_2    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
  if (pages == null || pages.length == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

  String[] pageRefs = new String[pages.length];

  for (int i = 0; i < pages.length; i++) {
    String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

    // the ref for this image
    pageRefs[i] = ref;

    // write the PNG in that directory
    PixmapIO.writePNG(outputDir.child(ref), pages[i]);
  }
  return pageRefs;
}
项目:Cubes_2    文件:Graphics.java   
public static void takeScreenshot() {
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight());
    FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
    dir.mkdirs();
    FileHandle f = dir.child(System.currentTimeMillis() + ".png");
    try {
        PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
        try {
            writer.setFlipY(true);
            writer.write(f, pixmap);
        } finally {
            writer.dispose();
        }
    } catch (IOException ex) {
        throw new CubesException("Error writing PNG: " + f, ex);
    } finally {
        pixmap.dispose();
    }
    Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
项目:enklave    文件:ProgressBarEnergy.java   
public void updateVisual(){
    Skin skin = new Skin();
    Pixmap pixmap = new Pixmap(1,(int)(Gdx.graphics.getHeight()*0.0175), Pixmap.Format.RGBA8888);
    switch (infoProfile.getDateUserGame().getFaction()){
        case 1:{
            pixmap.setColor(1, 0f, 0f, 1);
            break;
        }
        case 2:{
            pixmap.setColor(0f, 0.831f, 0.969f,1f);
            break;
        }
        case 3:{
            pixmap.setColor(0.129f, 0.996f, 0.29f,1);
            break;
        }
    }
    pixmap.fill();
    skin.add("blue", new Texture(pixmap));
    ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(bar.getStyle().background,skin.newDrawable("blue",Color.WHITE));
    style.knobBefore = style.knob;
    bar.setStyle(style);
}
项目:enklave    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:PixelDungeonTC    文件:TextureCache.java   
public static SmartTexture createSolid( int color ) {
    String key = "1x1:" + color;

    if (all.containsKey( key )) {

        return all.get( key );

    } else {

        final Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
        // In the rest of the code ARGB is used
        pixmap.setColor( (color << 8) | (color >>> 24) );
        pixmap.fill();
        GdxTexture bmp = new GdxTexture( pixmap );

        SmartTexture tx = new SmartTexture( bmp );
        all.put(key, tx);

        return tx;
    }
}
项目:Particles    文件:DisplayManager.java   
public Pixmap generateScreenshot(ParticleSystem particleSystem, Player player) {
    final float cam_width = camera.getCameraWidth();
    final float cam_height = camera.getCameraHeight();
    final int current_x = camera.getCameraX();
    final int current_y = camera.getCameraY();
    final Pixmap screen_shot = new Pixmap((int) cam_width, (int) cam_height, Pixmap.Format.RGB888);

    for (int i = current_x; i < current_x + cam_width; i++) {
        for (int j = current_y; j < current_y + cam_height; j++) {
            Particle current_particle = particleSystem.getParticle(i, j);

            if (current_particle != null) {
                screen_shot.setColor(current_particle.getProperties().getColor());
                screen_shot.drawPixel(i - current_x, ((int) cam_height - 1) - (j - current_y));
            }
        }
    }

    return screen_shot;
}
项目:MMORPG_Prototype    文件:GameObjectHighlightGraphic.java   
private Texture createHighlightingGraphic(TextureRegion textureRegion)
{
    TextureData textureData = textureRegion.getTexture().getTextureData();
    textureData.prepare();
    Pixmap sourcePixmap = textureData.consumePixmap();
    Pixmap destinationPixmap = new Pixmap(textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), Format.RGBA8888);
    Color color = new Color();

    for (int x = 0; x < textureRegion.getRegionWidth(); x++)
    {
        for (int y = 0; y < textureRegion.getRegionHeight(); y++)
        {
            int colorInt = sourcePixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y);
            Color.rgba8888ToColor(color, colorInt);
            destinationPixmap.setColor(1.0f, 1f, 1.0f, 1);
            if (color.a > 0.004f)
                destinationPixmap.drawPixel(x, y);
        }
    }
    Texture result = new Texture(destinationPixmap);
    textureData.disposePixmap();
    destinationPixmap.dispose();
    return result;
}
项目:ProjektGG    文件:CursorManager.java   
/**
 * Sets the cursor image.
 * 
 * @param image
 *            The image.
 */
public void setCursorImage(Pixmap image) {
    if (image == null) {
        throw new IllegalArgumentException("Cursor image cannot be null.");
    }

    if (!cursorCacheMap.containsKey(image)) {
        Cursor newCursor = Gdx.graphics.newCursor(image, 0, 0);
        this.cursorCacheMap.put(image, newCursor);

        Gdx.graphics.setCursor(newCursor);
    } else {
        Gdx.graphics.setCursor(cursorCacheMap.get(image));
    }
}
项目:Mindustry    文件:MapEditorDialog.java   
private boolean verifySize(Pixmap pix){
    boolean w = false, h = false;
    for(int i : MapEditor.validMapSizes){
        if(pix.getWidth() == i)
            w = true;
        if(pix.getHeight() == i)
            h = true;
    }

    return w && h;
}
项目:Mindustry    文件:MapEditorDialog.java   
private boolean verifyMap(){
    int psc = ColorMapper.getColor(SpecialBlocks.playerSpawn);
    int esc = ColorMapper.getColor(SpecialBlocks.enemySpawn);

    int playerSpawns = 0;
    int enemySpawns = 0;
    Pixmap pix = editor.pixmap();

    for(int x = 0; x < pix.getWidth(); x ++){
        for(int y = 0; y < pix.getHeight(); y ++){
            int i = pix.getPixel(x, y);
            if(i == psc) playerSpawns ++;
            if(i == esc) enemySpawns ++;
        }
    }

    if(playerSpawns == 0){
        Vars.ui.showError("$text.editor.noplayerspawn");
        return false;
    }else if(playerSpawns > 1){
        Vars.ui.showError("$text.editor.manyplayerspawns");
        return false;
    }

    if(enemySpawns > MapEditor.maxSpawnpoints){
        Vars.ui.showError(Bundles.format("text.editor.manyenemyspawns", MapEditor.maxSpawnpoints));
        return false;
    }

    return true;
}
项目:Mindustry    文件:MapEditor.java   
public void draw(int dx, int dy){
    if(dx < 0 || dy < 0 || dx >= pixmap.getWidth() || dy >= pixmap.getHeight()){
        return;
    }

    Gdx.gl.glBindTexture(GL20.GL_TEXTURE_2D, texture.getTextureObjectHandle());

    int dstWidth = brushSize*2-1;
    int dstHeight = brushSize*2-1;
    int width = pixmap.getWidth(), height = pixmap.getHeight();

    int x = dx - dstWidth/2;
    int y = dy - dstHeight/2;

    if (x + dstWidth > width){
        x = width - dstWidth;
    }else if (x < 0){
        x = 0;
    }

    if (y + dstHeight > height){
        dstHeight = height - y;
    }else if (y < 0){
        dstHeight += y;
        y = 0;
    }

    pixmap.fillCircle(dx, dy, brushSize-1);

    Pixmap dst = brush(brushSize);
    dst.drawPixmap(pixmap, x, y, dstWidth, dstHeight, 0, 0, dstWidth, dstHeight);

    Gdx.gl.glTexSubImage2D(GL20.GL_TEXTURE_2D, 0, x, y, dstWidth, dstHeight,
            dst.getGLFormat(), dst.getGLType(), dst.getPixels());
}
项目:Mindustry    文件:MapEditor.java   
private Pixmap brush(int size){
    for(int i = 0; i < brushSizes.length; i ++){
        if(brushSizes[i] == size){
            return brushPixmaps[i];
        }
    }
    return null;
}
项目:Planet-Generator    文件:PixelBuffer.java   
public PixelBuffer() {
    super(Pixmap.Format.RGBA8888, Scene.BUFFER_WIDTH, Scene.BUFFER_HEIGHT, false);
    getColorBufferTexture().setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);

    pixelBufferRegion = new TextureRegion(getColorBufferTexture(), 0, 0, Scene.BUFFER_WIDTH, Scene.BUFFER_HEIGHT);
    pixelBufferRegion.flip(false, true);
}
项目:Planet-Generator    文件:ObjectGenerator.java   
public Sprite createMoonSprite(int size) {
        Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888);
//        pixmap.setColor(color);
        pixmap.setColor(Color.WHITE);
        pixmap.fillCircle(pixmap.getWidth()/2, pixmap.getHeight()/2, size / 2 - 1);
        Sprite sprite = new Sprite(new Texture(pixmap));
        pixmap.dispose();
        return sprite;
    }
项目:Catan    文件:SignUpScreen.java   
private void createBasicSkin() {
    // Create a font
    BitmapFont font = new BitmapFont();
    skin = new Skin();
    skin.add("default", font);

    // Create a texture
    Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 10, Pixmap.Format.RGB888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("background", new Texture(pixmap));

    // Create a button style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("background", Color.GRAY);
    textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    // Create a window style
    Window.WindowStyle windowStyle = new Window.WindowStyle();
    windowStyle.background = skin.newDrawable("background", Color.DARK_GRAY);
    // Dim background
    windowStyle.stageBackground = skin.newDrawable("background", Color.valueOf("#00000099"));
    windowStyle.titleFont = skin.getFont("default");
    windowStyle.titleFontColor = Color.WHITE;
    skin.add("default", windowStyle);
}
项目:PixelDungeonTC    文件:ItemSprite.java   
public static int pick( int index, int x, int y ) {
    GdxTexture bmp = TextureCache.get( Assets.ITEMS ).bitmap;
    int rows = bmp.getWidth() / SIZE;
    int row = index / rows;
    int col = index % rows;
    // FIXME: I'm assuming this is super slow?
    final TextureData td = bmp.getTextureData();
    if (!td.isPrepared()) {
        td.prepare();
    }
    final Pixmap pixmap = td.consumePixmap();
    int pixel = pixmap.getPixel(col * SIZE + x, row * SIZE + y);
    pixmap.dispose();
    return pixel;
}
项目:NoRiskNoFun    文件:GameScene.java   
/**
 * Re-color a given region
 * @param color New Color for the Region
 * @param region Region to re-color
 */
private void setRegionColor(Color color, AssetMap.Region region) {
    Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pix.setColor(color);
    pix.fill();

    Texture regionTexture = new Texture(pix);
    PolygonRegion polygonRegion = regionMap.get(region);
    polygonRegion.getRegion().setTexture(regionTexture);
}
项目:odb-artax    文件:MyScreenUtils.java   
public static void putPixelsBack(Pixmap pixmap, ByteBuffer pixels) {
    if (pixmap.getWidth() == 0 || pixmap.getHeight() == 0) return;
    if (imageData == null) {
        imageData = pixmap.getContext().createImageData(pixmap.getHeight(), pixmap.getWidth());
    }
    putPixelsBack(pixels.array(), pixmap.getWidth(), pixmap.getHeight(), pixmap.getContext(), imageData);
}
项目:drc-sim-client    文件:TextureUtil.java   
public static Texture resizeTexture(String internalPath, int width, int height) {
    Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
    Pixmap origPixmap = new Pixmap(Gdx.files.internal(internalPath));
    pixmap.drawPixmap(origPixmap, 0, 0, origPixmap.getWidth(), origPixmap.getHeight(),
            0, 0, width, height);
    return new Texture(pixmap);
}
项目:GangsterSquirrel    文件:MainGameClass.java   
/**
 * Takes a screenshot of the current game state and saves it in the assets directory
 */
public void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.local("screenshots/screenshot.png"), pixmap);
    pixmap.dispose();
}
项目:SpaceChaos    文件:DefaultCursorManager.java   
@Override
public void setCursorTexture(Pixmap cursorImage) {
    this.cursor = null;

    if (this.newCursorImage != cursorImage) {
        this.newCursorImage = cursorImage;
        changed = true;
    }
}
项目:PixelDungeonTC    文件:BitmapText.java   
protected void splitBy(GdxTexture bitmap, int height, int color, String chars, String fntFile, int scale)
{
    autoUppercase = false;

    ArrayList<FntFileChar> realChars = processFntFile(fntFile, scale);

    int width = bitmap.getWidth();
    int length = realChars.size();

    TextureData td = bitmap.getTextureData();
    if (!td.isPrepared())
    {
        td.prepare();
    }
    final Pixmap pixmap = td.consumePixmap();

    for (int i = 0; i < length; i++)
    {
        FntFileChar ch = realChars.get(i);
        if (ch.c == ' ')
        {
            add(ch.c, new RectF(1 - (float) ch.height / 2 / width, 1 - (float) ch.height / height, 1, 1));
            // add('\u007F', new RectF(1 - (float)ch.height / 2 / width, 1 - (float)ch.height / height, 1, 1));
            // in case no such in font
        }
        else
        {
            add(ch.c, new RectF((float) ch.x / width, (float) ch.y / height, (float) (ch.x + ch.width) / width, (float) (ch.y + ch.height) / height));
        }
    }
    pixmap.dispose();

    lineHeight = baseLine = height(frames.get(realChars.get(0).c));
}
项目:libgdx-crypt-texture    文件:TextureDecryptor.java   
public static Texture loadTexture(Crypto crypto, FileHandle file, Pixmap.Format format, boolean useMipMaps) {
    try {
        byte[] bytes = file.readBytes();
        if (crypto != null) {
            bytes = crypto.decrypt(bytes, true);
        }
        Pixmap pixmap = new Pixmap(new Gdx2DPixmap(bytes, 0, bytes.length, 0));
        return new Texture(pixmap, format, useMipMaps);
    } catch (Exception e) {
        throw new GdxRuntimeException("Couldn't load file: " + file, e);
    }
}
项目:Cubes_2    文件:AOTextureGenerator.java   
protected static void generate(FileHandle file, float strength) {
    Pixmap blocks = new Pixmap(INDIVIDUAL_SIZE * 3, INDIVIDUAL_SIZE * 3, AOTextureGenerator.FORMAT);
    Pixmap gaussian = new Pixmap(INDIVIDUAL_SIZE, INDIVIDUAL_SIZE, AOTextureGenerator.FORMAT);

    Pixmap output = new Pixmap(TEXTURE_SIZE, TEXTURE_SIZE, AOTextureGenerator.FORMAT);

    double[][] gwm = AOTextureGenerator.gaussianWeightMatrix(SIGMA);
    int gaussianRadius = (gwm.length - 1) / 2;

    Color blockColor = new Color(strength, strength, strength, 1f);

    for (int i = 0; i < TOTAL; i++) {
        String n = name(i);
        System.out.print(n + " ");

        AOTextureGenerator.clearPixmap(blocks);
        AOTextureGenerator.clearPixmap(gaussian);

        AOTextureGenerator.setupPixmap(blocks, i, blockColor);

        AOTextureGenerator.gaussianPixmap(blocks, gaussian, gwm, gaussianRadius);

        // PixmapIO.writePNG(folder.child(n + "_blocks_" + sigma + ".png"),
        // blocks);
        // PixmapIO.writePNG(folder.child(n + "_gaussian_" + sigma +
        // ".png"), gaussian);

        output.drawPixmap(gaussian, (i % SQRT_TOTAL) * INDIVIDUAL_SIZE, (i / SQRT_TOTAL) * INDIVIDUAL_SIZE, 0, 0,
                INDIVIDUAL_SIZE, INDIVIDUAL_SIZE);

        if (i % SQRT_TOTAL == SQRT_TOTAL - 1)
            System.out.println();
    }

    PixmapIO.writePNG(file, output);
    output.dispose();
    blocks.dispose();
    gaussian.dispose();
}