Skip to content

Refactor FlxBitmapText rendering in renderTile #3394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft
15 changes: 8 additions & 7 deletions flixel/FlxSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -803,26 +803,26 @@ class FlxSprite extends FlxObject
*/
override public function draw():Void
{
checkClipRect();

checkEmptyFrame();

if (alpha == 0 || _frame.type == FlxFrameType.EMPTY)
return;

if (dirty) // rarely
calcFrame(useFramePixels);

checkClipRect();

for (camera in getCamerasLegacy())
{
if (!camera.visible || !camera.exists || !isOnScreen(camera))
continue;

if (isSimpleRender(camera))
drawSimple(camera);
else
drawComplex(camera);

#if FLX_DEBUG
FlxBasic.visibleCount++;
#end
Expand All @@ -839,7 +839,8 @@ class FlxSprite extends FlxObject
*/
function checkClipRect()
{
if ((clipRect == null && Math.isNaN(_lastClipRect.x))
if (frames == null
|| (clipRect == null && Math.isNaN(_lastClipRect.x))
|| (clipRect != null && clipRect.equals(_lastClipRect)))
return;

Expand Down
51 changes: 47 additions & 4 deletions flixel/graphics/frames/FlxFrame.hx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ class FlxFrame implements IFlxDestroyable

var blitMatrix:Vector<Float>;

@:allow(flixel.graphics.FlxGraphic)
@:allow(flixel.graphics.frames.FlxFramesCollection)
function new(parent:FlxGraphic, angle = FlxFrameAngle.ANGLE_0, flipX = false, flipY = false, duration = 0.0)
public function new(parent:FlxGraphic, angle = FlxFrameAngle.ANGLE_0, flipX = false, flipY = false, duration = 0.0)
{
this.parent = parent;
this.angle = angle;
Expand Down Expand Up @@ -584,7 +582,52 @@ class FlxFrame implements IFlxDestroyable
copyTo(clippedFrame);
return clippedFrame.clip(rect);
}


/**
* Whether there is any overlap between this frame and the given rect. If clipping this frame to
* the given rect would result in an empty frame, the result is `false`
*/
public function overlaps(rect:FlxRect)
{
rect.x += frame.x - offset.x;
rect.y += frame.y - offset.y;
final result = rect.overlaps(frame);
rect.x -= frame.x - offset.x;
rect.y -= frame.y - offset.y;
return result;
}


/**
* Whether this frame fully contains the given rect. If clipping this frame to
* the given rect would result in a smaller frame, the result is `false`
* @since 6.1.0
*/
public function contains(rect:FlxRect)
{
rect.x += frame.x - offset.x;
rect.y += frame.y - offset.y;
final result = frame.contains(rect);
rect.x -= frame.x - offset.x;
rect.y -= frame.y - offset.y;
return result;
}

/**
* Whether this frame is fully contained by the given rect. If clipping this frame to
* the given rect would result in a smaller frame, the result is `false`
* @since 6.1.0
*/
public function isContained(rect:FlxRect)
{
rect.x += frame.x - offset.x;
rect.y += frame.y - offset.y;
final result = rect.contains(frame);
rect.x -= frame.x - offset.x;
rect.y -= frame.y - offset.y;
return result;
}

/**
* Clips this frame to the desired rect
*
Expand Down
17 changes: 17 additions & 0 deletions flixel/math/FlxRect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ class FlxRect implements IFlxPooled
return result;
}

/**
* Checks to see if this rectangle fully contains another
*
* @param rect The other rectangle
* @return Whether this rectangle contains the given rectangle
* @since 6.1.0
*/
public inline function contains(rect:FlxRect):Bool
{
final result = rect.left >= left
&& rect.right <= right
&& rect.top >= top
&& rect.bottom <= bottom;
rect.putWeak();
return result;
}

/**
* Returns true if this FlxRect contains the FlxPoint
*
Expand Down
Loading