Skip to content

Commit

Permalink
FlxTilemap: add antialiasing (HaxeFlixel#1850)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsiusprime authored and Aurel300 committed Apr 17, 2018
1 parent 1498541 commit 53e3308
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion flixel/tile/FlxTilemap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class FlxTilemap extends FlxBaseTilemap<FlxTile>
*/
public var scale(default, null):FlxPoint;

/**
* Controls whether the object is smoothed when rotated, affects performance.
*/
public var antialiasing(default, set):Bool = false;

/**
* Use to offset the drawing position of the tilemap,
* just like FlxSprite.
Expand Down Expand Up @@ -806,7 +811,7 @@ class FlxTilemap extends FlxBaseTilemap<FlxTile>
scaledHeight = _scaledTileHeight;

var hasColorOffsets:Bool = (colorTransform != null && colorTransform.hasRGBAOffsets());
drawItem = Camera.startQuadBatch(graphic, isColored, hasColorOffsets, blend);
drawItem = Camera.startQuadBatch(graphic, isColored, hasColorOffsets, blend, antialiasing);
}

// Copy tile images into the tile buffer
Expand Down Expand Up @@ -970,6 +975,10 @@ class FlxTilemap extends FlxBaseTilemap<FlxTile>
{
var buffer = new FlxTilemapBuffer(_tileWidth, _tileHeight, widthInTiles, heightInTiles, camera, scale.x, scale.y);
buffer.pixelPerfectRender = pixelPerfectRender;
if (FlxG.renderBlit)
{
buffer.antialiasing = antialiasing;
}
return buffer;
}

Expand Down Expand Up @@ -1013,6 +1022,19 @@ class FlxTilemap extends FlxBaseTilemap<FlxTile>
}
#end

private function set_antialiasing(value:Bool):Bool
{
antialiasing = value;
if (FlxG.renderBlit)
{
for (buffer in _buffers)
{
buffer.antialiasing = antialiasing;
}
}
return antialiasing;
}

/**
* Internal function for setting graphic property for this object.
* It changes graphic' useCount also for better memory tracking.
Expand Down
3 changes: 2 additions & 1 deletion flixel/tile/FlxTilemapBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FlxTilemapBuffer implements IFlxDestroyable
public var pixels(default, null):BitmapData;

public var blend:BlendMode;
public var antialiasing:Bool = false;

private var _flashRect:Rectangle;
private var _matrix:Matrix;
Expand Down Expand Up @@ -137,7 +138,7 @@ class FlxTilemapBuffer implements IFlxDestroyable
_matrix.identity();
_matrix.scale(ScaleX, ScaleY);
_matrix.translate(FlashPoint.x, FlashPoint.y);
Camera.buffer.draw(pixels, _matrix, null, blend);
Camera.buffer.draw(pixels, _matrix, null, blend, null, antialiasing);
}
}

Expand Down

0 comments on commit 53e3308

Please sign in to comment.