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; }
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(); }
public static int pick( int index, int x, int y ) { Bitmap 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; }
@Override public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) { if (cls.getName().equals(BufferUtils.class.getName())) { transformBufferUtils(cls, innerSource); } else if (cls.getName().equals(TextureData.Factory.class.getName())) { transformTextureData(cls, innerSource); } else if (cls.getName().equals(FileHandle.class.getName())) { transformFileHandle(cls); } else if (cls.getName().equals(Pixmap.class.getName())) { replaceClass(cls, innerSource.get(PixmapEmulator.class.getName())); } else if (cls.getName().equals(Matrix4.class.getName())) { transformMatrix(cls, innerSource); } else if (cls.getName().equals(VertexArray.class.getName()) || cls.getName().equals(VertexBufferObject.class.getName())) { replaceClass(cls, innerSource.get(VertexArrayEmulator.class.getName())); } else if (cls.getName().equals(IndexArray.class.getName()) || cls.getName().equals(IndexBufferObject.class.getName())) { replaceClass(cls, innerSource.get(IndexArrayEmulator.class.getName())); } }
@Override public void consumeCubemapData () { for (int i = 0; i < data.length; i++) { if (data[i].getType() == TextureData.TextureDataType.Custom) { data[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); } else { Pixmap pixmap = data[i].consumePixmap(); boolean disposePixmap = data[i].disposePixmap(); if (data[i].getFormat() != pixmap.getFormat()) { Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[i].getFormat()); Blending blend = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); Pixmap.setBlending(blend); if (data[i].disposePixmap()) pixmap.dispose(); pixmap = tmp; disposePixmap = true; } Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1); Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); } } }
@Override public void loadAsync (AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) { info.filename = fileName; if (parameter == null || parameter.textureData == null) { Pixmap pixmap = null; Format format = null; boolean genMipMaps = false; info.texture = null; if (parameter != null) { format = parameter.format; genMipMaps = parameter.genMipMaps; info.texture = parameter.texture; } info.data = TextureData.Factory.loadFromFile(file, format, genMipMaps); } else { info.data = parameter.textureData; info.texture = parameter.texture; } if (!info.data.isPrepared()) info.data.prepare(); }
private static TextureData c(String paramString, boolean paramBoolean) { String str; if (paramBoolean) str = "-useMipMaps"; try { aj.a("AssetUtils.getTextureData", str); FileTextureData localFileTextureData = new FileTextureData((FileHandle)an.a(a(paramString)), null, null, paramBoolean); return localFileTextureData; str = ""; } finally { aj.b(); } }
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)); }
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; }
private static Cursor getCursorForPath(AssetManager am, String texturePath) { Pixmap pixmap = null; if (texturePath != null) { Texture cursorTexture = am.get(texturePath); TextureData data = cursorTexture.getTextureData(); if (!data.isPrepared()) { data.prepare(); } pixmap = data.consumePixmap(); } return Gdx.graphics.newCursor(pixmap, 0, 0); }
@Override protected Cubemap loadObject(FileHandle file) { Array<TextureData> textures = new Array<TextureData>(); for(String sideName : SIDES) { FileHandle sideHandle = Gdx.files.internal(file.pathWithoutExtension() + sideName + "." + file.extension()); if (sideHandle.exists()) { TextureAsset sideAsset = manager.getTexture(sideHandle.file().getAbsolutePath()); Texture texture = sideAsset.get(); addDependency(sideAsset); textures.add(texture.getTextureData()); } else { throw new GdxRuntimeException("Could not find " + sideHandle.path()); } } Cubemap cm = new Cubemap( textures.get(0), textures.get(1), textures.get(2), textures.get(3), textures.get(4), textures.get(5) ); cm.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge); cm.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); return cm; }
public Pixmap getPixmap() { if (pixmap == null) { TextureData textureData = get().getTextureData(); if (!textureData.isPrepared()) { textureData.prepare(); } pixmap = textureData.consumePixmap(); } return pixmap; }
/** Construct a Cubemap with the specified texture files for the sides, optionally generating mipmaps. */ public FacedCubemapData (FileHandle positiveX, FileHandle negativeX, FileHandle positiveY, FileHandle negativeY, FileHandle positiveZ, FileHandle negativeZ) { this(TextureData.Factory.loadFromFile(positiveX, false), TextureData.Factory.loadFromFile(negativeX, false), TextureData.Factory.loadFromFile(positiveY, false), TextureData.Factory.loadFromFile( negativeY, false), TextureData.Factory.loadFromFile(positiveZ, false), TextureData.Factory .loadFromFile(negativeZ, false)); }
/** Construct a Cubemap with the specified texture files for the sides, optionally generating mipmaps. */ public FacedCubemapData (FileHandle positiveX, FileHandle negativeX, FileHandle positiveY, FileHandle negativeY, FileHandle positiveZ, FileHandle negativeZ, boolean useMipMaps) { this(TextureData.Factory.loadFromFile(positiveX, useMipMaps), TextureData.Factory.loadFromFile( negativeX, useMipMaps), TextureData.Factory.loadFromFile(positiveY, useMipMaps), TextureData.Factory .loadFromFile(negativeY, useMipMaps), TextureData.Factory.loadFromFile(positiveZ, useMipMaps), TextureData.Factory.loadFromFile(negativeZ, useMipMaps)); }
/** Construct a Cubemap with the specified {@link TextureData}'s for the sides */ public FacedCubemapData (TextureData positiveX, TextureData negativeX, TextureData positiveY, TextureData negativeY, TextureData positiveZ, TextureData negativeZ) { data[0] = positiveX; data[1] = negativeX; data[2] = positiveY; data[3] = negativeY; data[4] = positiveZ; data[5] = negativeZ; }
private synchronized int calculateTextureSize(AssetManager assetManager, String fileName) { if (memoryPerFile.containsKey(fileName)) { return memoryPerFile.get(fileName); } Texture texture = assetManager.get(fileName, Texture.class); TextureData textureData = texture.getTextureData(); int textureSize = textureData.getWidth() * textureData.getHeight(); switch (textureData.getFormat()) { case RGB565: textureSize *= 2; break; case RGB888: textureSize *= 3; break; case RGBA4444: textureSize *= 2; break; case RGBA8888: textureSize *= 4; break; } if (textureData.useMipMaps()) { textureSize *= 1.33f; } memoryPerFile.put(fileName, textureSize); return textureSize; }
@Override public void drawCell(float x, float y, float width, float height, float r, float g, float b, float a) { Texture buffer = renderer.getBuffer(); if (buffer != null) { Pixmap map = new Pixmap((int)width, (int)height, Format.RGBA8888); map.setColor(r, g, b, a); if (image != null) { Sprite sprite = new Sprite(image); sprite.setColor(r, g, b, a); image = sprite.getTexture(); TextureData data = image.getTextureData(); data.prepare(); Pixmap tmp = data.consumePixmap(); map.drawPixmap(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), 0, 0, (int)width, (int)height); image.getTextureData().disposePixmap(); } else { map.fillRectangle(0, 0, (int)width, (int)height); } buffer.draw(map, (int)x, (int)y); map.dispose(); } }
public static TextureData b(String paramString, boolean paramBoolean) { try { aj.a("AssetUtils.prepareTextureData-", new File(paramString).getName()); TextureData localTextureData = c(paramString, paramBoolean); localTextureData.prepare(); return localTextureData; } finally { aj.b(); } }
public Texture (TextureData data) { super(data); }
public GdxTexture(TextureData data) { super(data); }
protected void splitBy(GdxTexture bitmap, int height, int color, String chars) { autoUppercase = chars.equals(LATIN_UPPER); int length = chars.length(); int width = bitmap.getWidth(); float vHeight = (float) height / bitmap.getHeight(); int pos; TextureData td = bitmap.getTextureData(); if (!td.isPrepared()) { td.prepare(); } final Pixmap pixmap = td.consumePixmap(); spaceMeasuring: for (pos = 0; pos < width; pos++) { for (int j = 0; j < height; j++) { if (colorNotMatch(pixmap, pos, j, color)) break spaceMeasuring; } } add(' ', new RectF(0, 0, (float) pos / width, vHeight)); for (int i = 0; i < length; i++) { char ch = chars.charAt(i); if (ch == ' ') { continue; } else { boolean found; int separator = pos; do { if (++separator >= width) { break; } found = true; for (int j = 0; j < height; j++) { if (colorNotMatch(pixmap, separator, j, color)) { found = false; break; } } } while (!found); add(ch, new RectF((float) pos / width, 0, (float) separator / width, vHeight)); pos = separator + 1; } } pixmap.dispose(); lineHeight = baseLine = height(frames.get(chars.charAt(0))); }
protected TextureData loadTexData(FileHandle file, Format format, boolean genMipMaps) { if (file.name().endsWith(".ktx") || file.name().endsWith(".zktx")) { return new KTXTextureData(file, genMipMaps); } return new PremultFileTextureData(file, format, genMipMaps); }
@Override protected TextureData loadTexData(FileHandle file, Format format, boolean genMipMaps) { return new JngTextureData(file, format, genMipMaps); }
public HeadlessTexture(TextureData data) { super(data); }
@Override public void load(TextureData data) { }
public Bitmap(TextureData data) { super(data); }
protected void splitBy(Bitmap bitmap, int height, int color, String chars) { autoUppercase = chars.equals(LATIN_UPPER); int length = chars.length(); int width = bitmap.getWidth(); float vHeight = (float) height / bitmap.getHeight(); int pos; TextureData td = bitmap.getTextureData(); if (!td.isPrepared()) { td.prepare(); } final Pixmap pixmap = td.consumePixmap(); //Don't be scared about the next lines. It's not a goto: implementation spaceMeasuring: for (pos = 0; pos < width; pos++) { for (int j = 0; j < height; j++) { if (colorNotMatch(pixmap, pos, j, color)) { break spaceMeasuring; } } } add(' ', new RectF(0, 0, (float) pos / width, vHeight)); for (int i = 0; i < length; i++) { char ch = chars.charAt(i); if (ch == ' ') { continue; } else { boolean found; int separator = pos; do { if (++separator >= width) { break; } found = true; for (int j = 0; j < height; j++) { if (colorNotMatch(pixmap, separator, j, color)) { found = false; break; } } } while (!found); add(ch, new RectF((float) pos / width, 0, (float) separator / width, vHeight)); pos = separator + 1; } } lineHeight = baseLine = height(frames.get(chars.charAt(0))); }
private void transformTextureData(ClassHolder cls, ClassReaderSource innerSource) { List<MethodDescriptor> descList = new ArrayList<>(); descList.add(new MethodDescriptor("loadFromFile", FileHandle.class, Format.class, boolean.class, TextureData.class)); replaceMethods(cls, TextureDataEmulator.class, innerSource, descList); }
public static TextureData loadFromFile(FileHandle file, Format format, boolean useMipMaps) { if (file == null) { return null; } return new FileTextureData(file, new Pixmap(file), format, useMipMaps); }
/** @param mipMapData must be != null and its length must be >= 1 */ public MipMapTextureData(TextureData... mipMapData){ mips = new TextureData[mipMapData.length]; System.arraycopy(mipMapData, 0, mips, 0, mipMapData.length); }
/** Construct an empty Cubemap. Use the load(...) methods to set the texture of each side. Every side of the cubemap must be set * before it can be used. */ public FacedCubemapData () { this((TextureData)null, (TextureData)null, (TextureData)null, (TextureData)null, (TextureData)null, (TextureData)null); }
@Override public boolean isManaged () { for (TextureData data : this.data) if (!data.isManaged()) return false; return true; }
/** @return The {@link TextureData} for the specified side, can be null if the cubemap is incomplete. */ public TextureData getTextureData (CubemapSide side) { return data[side.index]; }
public void build(int width, int height) { BlockFactory factory = new BlockFactory(this); if (data.length < data[0].length()) { blockSize = width / data[0].length(); } else { blockSize = height / data.length; } int mazeWidth = blockSize * data[0].length(); int mazeHeight = blockSize * data.length; mazeX = width / 2 - mazeWidth / 2; mazeY = height / 2 - mazeHeight / 2; Pixmap map = new Pixmap(mazeWidth, mazeHeight, Format.RGBA8888); Texture wall = Assets.getInstance().get(Assets.WALL, Texture.class); TextureData texData = wall.getTextureData(); texData.prepare(); Pixmap wallMap = texData.consumePixmap(); Texture floor = Assets.getInstance().get(Assets.FLOOR, Texture.class); TextureData floorData = floor.getTextureData(); floorData.prepare(); Pixmap floorMap = floorData.consumePixmap(); for (int y = 0; y < data.length; y++) { String line = data[y]; for (int x = 0; x < line.length(); ++x) { char character = line.charAt(x); map.drawPixmap(floorMap, 0, 0, wall.getWidth(), wall.getHeight(), x * blockSize, y * blockSize, blockSize, blockSize); if (character == '1') { map.setColor((float)(Math.random() * 0.5f + 0.5f), (float)(Math.random() * 0.5f + 0.5f), (float)(Math.random() * 0.5f + 0.5f), 1f); map.drawPixmap(wallMap, 0, 0, wall.getWidth(), wall.getHeight(), x * blockSize, y * blockSize, blockSize, blockSize); } if (character != ' ' && character != '\n' && character != '\r' && character != '\f') { Block block = factory.create(character, x, y); blocks.add(block); // Event handling if (block instanceof Monster) { Monster m = (Monster)block; m.addListener(this); m.addListener(particleHandler); monsters.add(m); if (!count.containsKey(m.getColor())) { count.put(m.getColor(), 1); } else { count.put(m.getColor(), count.get(m.getColor()) + 1); } } } } } wallMap.dispose(); floorMap.dispose(); sprite = new Sprite(new Texture(map)); sprite.flip(false, true); sprite.setPosition(mazeX, mazeY); map.dispose(); this.width = mazeWidth; this.height = mazeHeight; }
@Override public void drawText(String string, float x, float y, Paint paint) { if (bitmap == null) { // log.debug("no bitmap set"); return; } // IosPaint p = (IosPaint) paint; Pixmap pixmap = bitmap.pixmap; TextureData td = font.getRegion().getTexture().getTextureData(); if (!td.isPrepared()) td.prepare(); Pixmap f = td.consumePixmap(); int adv = (int) x; Glyph last = null; int ch = (int) font.getCapHeight(); int h = (int) font.getLineHeight(); int yy = (int) (y - font.getLineHeight()); if (y < 0) y = 0; // pixmap.setColor(0xff0000ff); // int w = (int) font.getBounds(string).width; // pixmap.drawRectangle((int) x - 4, (int) y - 4, w + 8, h + 8); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); Glyph g = font.getData().getGlyph(c); if (g == null) g = font.getData().getGlyph(' '); if (i > 0) adv += last.getKerning(c); pixmap.drawPixmap(f, adv, //- g.xoffset, yy - (g.height + g.yoffset) - (h - ch), g.srcX, g.srcY, g.width, g.height); adv += g.width; last = g; } }
public Array<Particle> pixelify() { int fac = pixfac * pixffac; if (fac < 0) { fac = 1; } //pixfac = 2; //DEBUG LINE, COMMENT WHOLE LINE OUT IF NOT DEBUGGING! Array<Particle> particles = new Array<Particle>(); for (int id : imgIDs) { Image img = getImage(id); TextureRegion texreg = getTexture(id); Texture tex = texreg.getTexture(); TextureData texdata = tex.getTextureData(); if (!texdata.isPrepared()) { texdata.prepare(); } Pixmap pixmap = texdata.consumePixmap(); int tx = texreg.getRegionX(); int ty = texreg.getRegionY(); int tw = texreg.getRegionWidth(); int th = texreg.getRegionHeight(); float w = rec.width; float h = rec.height; float pixw = w / tw * fac; float pixh = h / th * fac; for (int yy = ty; yy < ty + th; yy += fac) { for (int xx = tx; xx < tx + tw; xx += fac) { int rgba = pixmap.getPixel(xx, yy); for (int yyy = 0; yyy < fac; yyy++) { for (int xxx = 0; xxx < fac; xxx++) { c.set(0f, 0f, 0f, 0f); cc.set(0f, 0f, 0f, 0f); Color.rgba8888ToColor(c, rgba); Color.rgba8888ToColor(cc, pixmap.getPixel(xx + xxx, yy + yyy)); c.mul(0.5f); cc.mul(0.5f); c.add(cc); rgba = Color.rgba8888(c); } } //System.out.println("X: "+xx+"; Y: "+yy+"; RGBA: "+Integer.toHexString(rgba)); Color.rgba8888ToColor(ccc, rgba); ccc.mul(img.getColor()); if (c.a < 0.0625f) continue; ppos.set(pos.x + ((xx - tx) * pixw / fac) + renderoffs.x, pos.y + ((yy - ty) * pixh / fac) + renderoffs.y); Particle pp = layer.level.systems.get(IParticleManager.class).create("PixelParticle", ppos, layer, ccc, pixw, 0); layer.add(pp); particles.add(pp); } } if (texdata.disposePixmap()) { pixmap.dispose(); } } return particles; }
public void addSequence(String name, TextureAtlas atlas, int tileToBeAnimated, int start, int stop, float delay, boolean loop) { if (animations.containsKey(name)) throw new UnsupportedOperationException("Duplicate animation sequence name."); if (atlas.texture.getTextureData().getType() != TextureData.TextureDataType.Pixmap) throw new UnsupportedOperationException("This only works with Textures backed by Pixmap texture data."); AnimationSequence sequence = new AnimationSequence(); sequence.atlas = atlas; sequence.animatingIndex = tileToBeAnimated; sequence.start = start; sequence.stop = stop; sequence.delay = delay; sequence.isAnimating = true; sequence.loop = loop; sequence.frames = new Pixmap[sequence.getNumFrames()]; sequence.current = sequence.start; sequence.currentFrameTime = 0.0f; // build up some CPU-side cache's of image data from the original TextureAtlas texture. we grab the image data // for the tile we're placing animation frames to so we can restore the original texture when/if needed. and we // grab each of the tiles that appear in the animation sequence so we can quickly upload it to the texture when // we're at that frame // grab the TextureAtlas texture's image data TextureData textureData = atlas.texture.getTextureData(); if (!textureData.isPrepared()) textureData.prepare(); Pixmap textureImage = textureData.consumePixmap(); // copy the image data for the destination animation tile region TextureRegion tileRegion = atlas.get(tileToBeAnimated); sequence.originalAnimatingTile = new Pixmap(tileRegion.getRegionWidth(), tileRegion.getRegionHeight(), textureData.getFormat()); sequence.originalAnimatingTile.drawPixmap( textureImage, 0, 0, tileRegion.getRegionX(), tileRegion.getRegionY(), tileRegion.getRegionWidth(), tileRegion.getRegionHeight() ); // copy image data for each of the animation sequence tiles (from "start" to and including "stop") for (int i = 0; i < sequence.getNumFrames(); ++i) { TextureRegion tile = atlas.get(i + sequence.start); sequence.frames[i] = new Pixmap(tileRegion.getRegionWidth(), tileRegion.getRegionHeight(), textureData.getFormat()); sequence.frames[i].drawPixmap( textureImage, 0, 0, tile.getRegionX(), tile.getRegionY(), tile.getRegionWidth(), tile.getRegionHeight() ); } // may need to dispose of the TextureAtlas's texture Pixmap that we obtained (depending on TextureData implementation) if (textureData.disposePixmap()) textureImage.dispose(); // all good! animations.put(name, sequence); }
/** * Fills the block with a randomly arranged selection of graphics from the image provided. * @param TileGraphic The graphic class that contains the tiles that should fill this block. * @param TileWidth The width of a single tile in the graphic. * @param TileHeight The height of a single tile in the graphic. * @param Empties The number of "empty" tiles to add to the auto-fill algorithm (e.g. 8 tiles + 4 empties = 1/3 of block will be open holes). */ public B2FlxTileblock loadTiles(String TileGraphic, int TileWidth, int TileHeight, int Empties) { if(TileGraphic == null) return this; //First create a tile brush FlxSprite sprite = new FlxSprite().loadGraphic(TileGraphic,true,false,TileWidth,TileHeight); int spriteWidth = (int) sprite.width; int spriteHeight = (int) sprite.height; int total = sprite.getNumFrames() + Empties; //Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries) boolean regen = false; if(width % sprite.width != 0) { width = (int)(width/spriteWidth+1)*spriteWidth; regen = true; } if(height % sprite.height != 0) { height = (int)(height/spriteHeight+1)*spriteHeight; regen = true; } if(regen) makeGraphic((int)width,(int)height,0,true); else this.fill(0); TextureData brushTextureData = sprite.framePixels.getTexture().getTextureData(); if(!brushTextureData.isPrepared()) brushTextureData.prepare(); Pixmap brushPixmap = brushTextureData.consumePixmap(); //Stamp random tiles onto the canvas int row = 0; int column; int destinationX; int destinationY = 0; int widthInTiles = (int) (width/spriteWidth); int heightInTiles = (int) (height/spriteHeight); while(row < heightInTiles) { destinationX = 0; column = 0; while(column < widthInTiles) { if(FlxG.random()*total > Empties) { sprite.randomFrame(); sprite.drawFrame(); stamp(brushPixmap, sprite.framePixels.getRegionX(), sprite.framePixels.getRegionY() - sprite.frameHeight, sprite.frameWidth, sprite.frameHeight, destinationX + _pixels.getRegionX(), destinationY + _pixels.getRegionY()); } destinationX += spriteWidth; column++; } destinationY += spriteHeight; row++; } if (brushTextureData.disposePixmap()) brushPixmap.dispose(); return this; }
public TextureData.TextureDataType getType() { return TextureData.TextureDataType.Compressed; }
public TextureData.TextureDataType getType() { return TextureData.TextureDataType.Pixmap; }