diff --git a/flixel/FlxObject.hx b/flixel/FlxObject.hx index bff324c41a..94a44ef091 100644 --- a/flixel/FlxObject.hx +++ b/flixel/FlxObject.hx @@ -5,6 +5,7 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.math.FlxVelocity; import flixel.path.FlxPath; +import flixel.system.debug.FlxDebugDrawGraphic; import flixel.tile.FlxBaseTilemap; import flixel.util.FlxAxes; import flixel.util.FlxColor; @@ -1274,11 +1275,10 @@ class FlxObject extends FlxBasic } - function drawDebugBoundingBoxColor(gfx:Graphics, rect:FlxRect, color:FlxColor) + function drawDebugBoundingBoxColor(gfx:FlxDebugDrawGraphic, rect:FlxRect, color:FlxColor) { - // fill static graphics object with square shape - gfx.lineStyle(1, color, 0.75); - gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); + color.alphaFloat = 0.75; + gfx.drawBoundingBox(rect.x, rect.y, rect.width, rect.height, color, 1.0); } inline function beginDrawDebug(camera:FlxCamera):Graphics diff --git a/flixel/path/FlxBasePath.hx b/flixel/path/FlxBasePath.hx index 3fa14e379a..b599d0f155 100644 --- a/flixel/path/FlxBasePath.hx +++ b/flixel/path/FlxBasePath.hx @@ -4,6 +4,7 @@ import flixel.FlxBasic; import flixel.FlxG; import flixel.FlxObject; import flixel.math.FlxPoint; +import flixel.system.debug.FlxDebugDrawGraphic; import flixel.util.FlxAxes; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; @@ -396,25 +397,18 @@ class FlxTypedBasePath extends FlxBasic implements IFlxDestroy return result; } - inline function drawNode(gfx:Graphics, node:FlxPoint, size:Int, color:FlxColor) + inline function drawNode(gfx:FlxDebugDrawGraphic, node:FlxPoint, size:Int, color:FlxColor) { - gfx.beginFill(color.rgb, color.alphaFloat); - gfx.lineStyle(); - final offset = Math.floor(size * 0.5); - gfx.drawRect(node.x - offset, node.y - offset, size, size); - gfx.endFill(); + final offset = size * 0.5; + gfx.drawRect(node.x - offset, node.y - offset, size, size, color); } - function drawLine(gfx:Graphics, node1:FlxPoint, node2:FlxPoint) + function drawLine(gfx:FlxDebugDrawGraphic, p1:FlxPoint, p2:FlxPoint) { - // then draw a line to the next node final color = debugDrawData.lineColor; final size = debugDrawData.lineSize; - gfx.lineStyle(size, color.rgb, color.alphaFloat); - - final lineOffset = debugDrawData.lineSize / 2; - gfx.moveTo(node1.x + lineOffset, node1.y + lineOffset); - gfx.lineTo(node2.x + lineOffset, node2.y + lineOffset); + final half = debugDrawData.lineSize / 2; + gfx.drawLine(p1.x + half, p1.y + half, p2.x + half, p2.y + half, color, size); } #end } diff --git a/flixel/system/debug/FlxDebugDrawGraphic.hx b/flixel/system/debug/FlxDebugDrawGraphic.hx new file mode 100644 index 0000000000..b54cca1df0 --- /dev/null +++ b/flixel/system/debug/FlxDebugDrawGraphic.hx @@ -0,0 +1,49 @@ +package flixel.system.debug; + +import flixel.FlxG; +import flixel.math.FlxPoint; +import flixel.util.FlxColor; +import openfl.display.Graphics; + +abstract FlxDebugDrawGraphic(Graphics) from Graphics to Graphics +{ + inline function useHardware(sizeSquared:Float) + { + return FlxG.renderTile && sizeSquared > 100 * 100; + } + + public function drawBoundingBox(x:Float, y:Float, width:Float, height:Float, color:FlxColor, thickness = 1.0) + { + if (useHardware(width * height)) + { + this.beginFill(color.rgb, color.alphaFloat); + this.drawRect(x, y, thickness, height); // left + this.drawRect(x + thickness, y, width - thickness * 2, thickness); // top + this.drawRect(x + width - thickness, y, thickness, height); // right + this.drawRect(x + thickness, y + height - thickness, width - thickness * 2, thickness); // bottom + this.endFill(); + } + else + { + this.lineStyle(thickness, color.rgb, color.alphaFloat); + final half = thickness * 0.5; + + this.drawRect(x + half, y + half, width - thickness, height - thickness); + } + } + + public function drawLine(x1:Float, y1:Float, x2:Float, y2:Float, color:FlxColor, thickness = 1.0) + { + this.lineStyle(thickness, color.rgb, color.alphaFloat); + + this.moveTo(x1, y1); + this.lineTo(x2, y2); + } + + public function drawRect(x:Float, y:Float, width:Float, height:Float, color:FlxColor) + { + this.beginFill(color.rgb, color.alphaFloat); + this.drawRect(x, y, width, height); + this.endFill(); + } +} diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index 80aecfc4d9..8aca73b595 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -14,8 +14,8 @@ import flixel.math.FlxMath; import flixel.math.FlxMatrix; import flixel.math.FlxPoint; import flixel.math.FlxRect; -import flixel.system.FlxAssets.FlxShader; -import flixel.system.FlxAssets.FlxTilemapGraphicAsset; +import flixel.system.FlxAssets; +import flixel.system.debug.FlxDebugDrawGraphic; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; import flixel.util.FlxDirectionFlags;