java类com.badlogic.gdx.graphics.Pixmap的实例源码

ScreenshotUtils.java 文件源码 项目:ProjektGG 阅读 34 收藏 0 点赞 0 评论 0
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();
}
BitmapFontWriter.java 文件源码 项目:Cubes 阅读 34 收藏 0 点赞 0 评论 0
/** 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;
}
LudumDare38.java 文件源码 项目:LD38-Compo 阅读 30 收藏 0 点赞 0 评论 0
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);
}
LudumDare38.java 文件源码 项目:LD38-Compo 阅读 31 收藏 0 点赞 0 评论 0
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);
}
LudumDare38.java 文件源码 项目:LD38-Compo 阅读 35 收藏 0 点赞 0 评论 0
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);
}
TileData.java 文件源码 项目:LD38-Compo 阅读 26 收藏 0 点赞 0 评论 0
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);
}
Graphics.java 文件源码 项目:Cubes 阅读 30 收藏 0 点赞 0 评论 0
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() + "'");
}
PatternTableManager.java 文件源码 项目:ggvm 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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();
}
Maps.java 文件源码 项目:Mindustry 阅读 33 收藏 0 点赞 0 评论 0
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();
}
Maps.java 文件源码 项目:Mindustry 阅读 27 收藏 0 点赞 0 评论 0
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;
    }
}
PlanetStencilSystem.java 文件源码 项目:odb-little-fortune-planet 阅读 29 收藏 0 点赞 0 评论 0
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();
}
DrawableMap.java 文件源码 项目:Climatar 阅读 26 收藏 0 点赞 0 评论 0
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());
}
TileTouchCheck.java 文件源码 项目:miniventure 阅读 26 收藏 0 点赞 0 评论 0
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;
        }
    }
}
Player.java 文件源码 项目:TH902 阅读 25 收藏 0 点赞 0 评论 0
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]);
}
VRCamera.java 文件源码 项目:Tower-Defense-Galaxy 阅读 25 收藏 0 点赞 0 评论 0
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;
}
AOTextureGenerator.java 文件源码 项目:Cubes_2 阅读 25 收藏 0 点赞 0 评论 0
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);
    }
}
BitmapFontWriter.java 文件源码 项目:Cubes_2 阅读 23 收藏 0 点赞 0 评论 0
/** 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;
}
Graphics.java 文件源码 项目:Cubes_2 阅读 29 收藏 0 点赞 0 评论 0
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() + "'");
}
ProgressBarEnergy.java 文件源码 项目:enklave 阅读 27 收藏 0 点赞 0 评论 0
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);
}
BitmapFontWriter.java 文件源码 项目:enklave 阅读 25 收藏 0 点赞 0 评论 0
/** 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;
}
TextureCache.java 文件源码 项目:PixelDungeonTC 阅读 22 收藏 0 点赞 0 评论 0
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;
    }
}
DisplayManager.java 文件源码 项目:Particles 阅读 65 收藏 0 点赞 0 评论 0
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;
}
GameObjectHighlightGraphic.java 文件源码 项目:MMORPG_Prototype 阅读 28 收藏 0 点赞 0 评论 0
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;
}
CursorManager.java 文件源码 项目:ProjektGG 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
MapEditorDialog.java 文件源码 项目:Mindustry 阅读 26 收藏 0 点赞 0 评论 0
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;
}
MapEditorDialog.java 文件源码 项目:Mindustry 阅读 19 收藏 0 点赞 0 评论 0
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;
}
MapEditor.java 文件源码 项目:Mindustry 阅读 37 收藏 0 点赞 0 评论 0
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());
}
MapEditor.java 文件源码 项目:Mindustry 阅读 36 收藏 0 点赞 0 评论 0
private Pixmap brush(int size){
    for(int i = 0; i < brushSizes.length; i ++){
        if(brushSizes[i] == size){
            return brushPixmaps[i];
        }
    }
    return null;
}
PixelBuffer.java 文件源码 项目:Planet-Generator 阅读 33 收藏 0 点赞 0 评论 0
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);
}
ObjectGenerator.java 文件源码 项目:Planet-Generator 阅读 21 收藏 0 点赞 0 评论 0
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;
    }


问题


面经


文章

微信
公众号

扫码关注公众号