/** * This function draws or stamps one <code>FlxSprite</code> onto another. This function is NOT * intended to replace <code>draw()</code>! * * @param Brush The image you want to use as a brush or stamp or pen or whatever. * @param SourceX The X coordinate of the brush's top left corner. * @param SourceY They Y coordinate of the brush's top left corner. * @param SourceWidth The brush's width. * @param SourceHeight The brush's height. * @param DestinationX The X coordinate of the brush's top left corner on this sprite. * @param DestinationY The Y coordinate of the brush's top right corner on this sprite. */ public void stamp( Pixmap Brush, int SourceX, int SourceY, int SourceWidth, int SourceHeight, int DestinationX, int DestinationY) { Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); TextureData textureData = null; if (_newTextureData != null) textureData = _newTextureData; else textureData = _pixels.getTexture().getTextureData(); if (!textureData.isPrepared()) textureData.prepare(); Pixmap pixmap = textureData.consumePixmap(); pixmap.drawPixmap( Brush, SourceX, SourceY, SourceWidth, SourceHeight, DestinationX, DestinationY, SourceWidth, SourceHeight); _newTextureData = new ManagedTextureData(pixmap); }
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; }
/** * Fills this sprite's graphic with a specific color. * * @param Color The color with which to fill the graphic, format 0xAARRGGBB. */ public void fill(int Color) { Pixmap.setBlending(Pixmap.Blending.SourceOver); Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); TextureData textureData = null; if (_newTextureData != null) textureData = _newTextureData; else textureData = _pixels.getTexture().getTextureData(); if (!textureData.isPrepared()) textureData.prepare(); Pixmap pixmap = textureData.consumePixmap(); pixmap.setColor(FlxU.argbToRgba(Color)); pixmap.fillRectangle( _pixels.getRegionX(), _pixels.getRegionY(), _pixels.getRegionWidth(), _pixels.getRegionHeight()); _newTextureData = new ManagedTextureData(pixmap); }
/** * This function draws a line on this sprite from position X1,Y1 to position X2,Y2 with the * specified color. * * @param StartX X coordinate of the line's start point. * @param StartY Y coordinate of the line's start point. * @param EndX X coordinate of the line's end point. * @param EndY Y coordinate of the line's end point. * @param Color The line's color, format 0xAARRGGBB. * @param Thickness How thick the line is in pixels (default value is 1). Note - unimplemented. */ public void drawLine( float StartX, float StartY, float EndX, float EndY, int Color, int Thickness) { Pixmap.setBlending(Pixmap.Blending.SourceOver); Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); TextureData textureData = null; if (_newTextureData != null) textureData = _newTextureData; else textureData = _pixels.getTexture().getTextureData(); if (!textureData.isPrepared()) textureData.prepare(); int rx = _pixels.getRegionX(); int ry = _pixels.getRegionY(); Pixmap pixmap = textureData.consumePixmap(); pixmap.setColor(FlxU.argbToRgba(Color)); pixmap.drawLine((int) (rx + StartX), (int) (ry + StartY), (int) (rx + EndX), (int) (ry + EndY)); _newTextureData = new ManagedTextureData(pixmap); }
/** * This function draws or stamps one <code>FlxSprite</code> onto another. This function is NOT * intended to replace <code>draw()</code>! * * @param Brush The image you want to use as a brush or stamp or pen or whatever. * @param X The X coordinate of the brush's top left corner on this sprite. * @param Y The Y coordinate of the brush's top left corner on this sprite. */ public void stamp(FlxSprite Brush, int X, int Y) { Brush.drawFrame(); TextureData brushTextureData = Brush.framePixels.getTexture().getTextureData(); if (!brushTextureData.isPrepared()) brushTextureData.prepare(); Pixmap brushPixmap = brushTextureData.consumePixmap(); stamp( brushPixmap, Brush.framePixels.getRegionX(), Brush.framePixels.getRegionY() - Brush.frameHeight, Brush.frameWidth, Brush.frameHeight, X + _pixels.getRegionX(), Y + _pixels.getRegionY()); if (brushTextureData.disposePixmap()) brushPixmap.dispose(); }
/** * Replace the color with a new color. * * @param Color The color that needs to be replaced. * @param NewColor The new color that will replaced the old one. * @param FetchPositions Whether the positions where the color is replaced should be saved or not. * @return An array of <code>FlxPoint</code>s that points where the color is replaced. */ public Array<FlxPoint> replaceColor(int Color, int NewColor, boolean FetchPositions) { Array<FlxPoint> positions = null; if (FetchPositions) positions = new Array<FlxPoint>(); Color = FlxU.argbToRgba(Color); NewColor = FlxU.argbToRgba(NewColor); int row = _pixels.getRegionY(); int column; int rows = _pixels.getRegionHeight() + row; int columns = _pixels.getRegionWidth() + _pixels.getRegionX(); Pixmap.setBlending(Pixmap.Blending.None); Pixmap.setFilter(Pixmap.Filter.NearestNeighbour); TextureData textureData = null; if (_newTextureData != null) textureData = _newTextureData; else textureData = _pixels.getTexture().getTextureData(); if (!textureData.isPrepared()) textureData.prepare(); Pixmap pixmap = textureData.consumePixmap(); while (row < rows) { column = _pixels.getRegionX(); while (column < columns) { if (pixmap.getPixel(column, row) == Color) { pixmap.drawPixel(column, row, NewColor); if (FetchPositions) positions.add(new FlxPoint(column - _pixels.getRegionX(), row - _pixels.getRegionY())); } column++; } row++; } _newTextureData = new ManagedTextureData(pixmap); return positions; }