From 8216425b8b5c0f13eec618cb49f3705c6e5d2046 Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Sat, 13 Apr 2024 00:45:32 +0200 Subject: [PATCH 1/3] Update FlxBackdrop.hx --- flixel/addons/display/FlxBackdrop.hx | 76 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/flixel/addons/display/FlxBackdrop.hx b/flixel/addons/display/FlxBackdrop.hx index cdc498a5..0a708bb5 100644 --- a/flixel/addons/display/FlxBackdrop.hx +++ b/flixel/addons/display/FlxBackdrop.hx @@ -49,6 +49,8 @@ class FlxBackdrop extends FlxSprite */ public var blitMode:BackdropBlitMode = AUTO; + var _tileSize:FlxPoint = FlxPoint.get(); + var _tileMatrix:FlxMatrix = new FlxMatrix(); var _blitOffset:FlxPoint = FlxPoint.get(); var _blitGraphic:FlxGraphic = null; var _prevDrawParams:BackdropDrawParams = @@ -82,9 +84,11 @@ class FlxBackdrop extends FlxSprite override function destroy():Void { - spacing = FlxDestroyUtil.destroy(spacing); - _blitOffset = FlxDestroyUtil.destroy(_blitOffset); + spacing = FlxDestroyUtil.put(spacing); + _tileSize = FlxDestroyUtil.put(_tileSize); + _blitOffset = FlxDestroyUtil.put(_blitOffset); _blitGraphic = FlxDestroyUtil.destroy(_blitGraphic); + _tileMatrix = null; super.destroy(); } @@ -273,14 +277,11 @@ class FlxBackdrop extends FlxSprite frame.prepareMatrix(_matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY()); _matrix.translate(-origin.x, -origin.y); - - // The distance between repeated sprites, in screen space - var tileSize = FlxPoint.get(frame.frame.width, frame.frame.height); - + if (drawDirect) { - tileSize.set - ( + // The distance between repeated sprites, in screen space + tileSize.set( (frame.frame.width + spacing.x) * scale.x, (frame.frame.height + spacing.y) * scale.y ); @@ -295,6 +296,10 @@ class FlxBackdrop extends FlxSprite _matrix.rotateWithTrig(_cosAngle, _sinAngle); } } + else + { + _tileSize.set(frame.frame.width, frame.frame.height); + } var drawItem = null; if (FlxG.renderTile) @@ -311,57 +316,54 @@ class FlxBackdrop extends FlxSprite getScreenPosition(_point, camera).subtractPoint(offset); var tilesX = 1; var tilesY = 1; - if (repeatAxes != NONE) + final viewMargins = camera.getViewMarginRect(); + final bounds = getScreenBounds(camera); + if (repeatAxes.x) { - final viewMargins = camera.getViewMarginRect(); - final bounds = getScreenBounds(camera); - if (repeatAxes.x) - { - final origTileSizeX = (frameWidth + spacing.x) * scale.x; - final left = modMin(bounds.right, origTileSizeX, viewMargins.left) - bounds.width; - final right = modMax(bounds.left, origTileSizeX, viewMargins.right) + origTileSizeX; - tilesX = Math.round((right - left) / tileSize.x); - _point.x = left + _point.x - bounds.x; - } + final origTileSizeX = (frameWidth + spacing.x) * scale.x; + final left = modMin(bounds.right, origTileSizeX, viewMargins.left) - bounds.width; + final right = modMax(bounds.left, origTileSizeX, viewMargins.right) + origTileSizeX; + tilesX = Math.round((right - left) / tileSize.x); + _point.x = left + _point.x - bounds.x; + } - if (repeatAxes.y) - { - final origTileSizeY = (frameHeight + spacing.y) * scale.y; - final top = modMin(bounds.bottom, origTileSizeY, viewMargins.top) - bounds.height; - final bottom = modMax(bounds.top, origTileSizeY, viewMargins.bottom) + origTileSizeY; - tilesY = Math.round((bottom - top) / tileSize.y); - _point.y = top + _point.y - bounds.y; - } - viewMargins.put(); - bounds.put(); + if (repeatAxes.y) + { + final origTileSizeY = (frameHeight + spacing.y) * scale.y; + final top = modMin(bounds.bottom, origTileSizeY, viewMargins.top) - bounds.height; + final bottom = modMax(bounds.top, origTileSizeY, viewMargins.bottom) + origTileSizeY; + tilesY = Math.round((bottom - top) / tileSize.y); + _point.y = top + _point.y - bounds.y; } + viewMargins.put(); + bounds.put(); + _point.addPoint(origin); if (drawBlit) _point.addPoint(_blitOffset); - - final mat = new FlxMatrix(); + for (tileX in 0...tilesX) { for (tileY in 0...tilesY) { - mat.copyFrom(_matrix); + _tileMatrix.copyFrom(_matrix); - mat.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY)); + _tileMatrix.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY)); if (isPixelPerfectRender(camera)) { - mat.tx = Math.floor(mat.tx); - mat.ty = Math.floor(mat.ty); + _tileMatrix.tx = Math.floor(_tileMatrix.tx); + _tileMatrix.ty = Math.floor(_tileMatrix.ty); } if (FlxG.renderBlit) { final pixels = drawBlit ? _blitGraphic.bitmap: framePixels; - camera.drawPixels(frame, pixels, mat, colorTransform, blend, antialiasing, shader); + camera.drawPixels(frame, pixels, _tileMatrix, colorTransform, blend, antialiasing, shader); } else { - drawItem.addQuad(frame, mat, colorTransform); + drawItem.addQuad(frame, _tileMatrix, colorTransform); } } } From 0b3fa643029efefae4a2997b45032f5793aff043 Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Sat, 13 Apr 2024 01:07:48 +0200 Subject: [PATCH 2/3] whoops missed these --- flixel/addons/display/FlxBackdrop.hx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/flixel/addons/display/FlxBackdrop.hx b/flixel/addons/display/FlxBackdrop.hx index 0a708bb5..f969113b 100644 --- a/flixel/addons/display/FlxBackdrop.hx +++ b/flixel/addons/display/FlxBackdrop.hx @@ -204,9 +204,9 @@ class FlxBackdrop extends FlxSprite final frame = drawBlit ? _blitGraphic.imageFrame.frame : _frame; // The distance between repeated sprites, in screen space - var tileSize = FlxPoint.get(frame.frame.width, frame.frame.height); + _tileSize.set(frame.frame.width, frame.frame.height); if (drawDirect) - tileSize.addPoint(spacing); + _tileSize.addPoint(spacing); getScreenPosition(_point, camera).subtractPoint(offset); var tilesX = 1; @@ -216,18 +216,18 @@ class FlxBackdrop extends FlxSprite final viewMargins = camera.getViewMarginRect(); if (repeatAxes.x) { - final left = modMin(_point.x + frameWidth, tileSize.x, viewMargins.left) - frameWidth; - final right = modMax(_point.x, tileSize.x, viewMargins.right) + tileSize.x; - tilesX = Math.round((right - left) / tileSize.x); + final left = modMin(_point.x + frameWidth, _tileSize.x, viewMargins.left) - frameWidth; + final right = modMax(_point.x, _tileSize.x, viewMargins.right) + _tileSize.x; + tilesX = Math.round((right - left) / _tileSize.x); final origTileSizeX = frameWidth + spacing.x; _point.x = modMin(_point.x + frameWidth, origTileSizeX, viewMargins.left) - frameWidth; } if (repeatAxes.y) { - final top = modMin(_point.y + frameHeight, tileSize.y, viewMargins.top) - frameHeight; - final bottom = modMax(_point.y, tileSize.y, viewMargins.bottom) + tileSize.y; - tilesY = Math.round((bottom - top) / tileSize.y); + final top = modMin(_point.y + frameHeight, _tileSize.y, viewMargins.top) - frameHeight; + final bottom = modMax(_point.y, _tileSize.y, viewMargins.bottom) + _tileSize.y; + tilesY = Math.round((bottom - top) / _tileSize.y); final origTileSizeY = frameHeight + spacing.y; _point.y = modMin(_point.y + frameHeight, origTileSizeY, viewMargins.top) - frameHeight; } @@ -247,7 +247,7 @@ class FlxBackdrop extends FlxSprite for (tileY in 0...tilesY) { // _point.copyToFlash(_flashPoint); - _flashPoint.setTo(_point.x + tileSize.x * tileX, _point.y + tileSize.y * tileY); + _flashPoint.setTo(_point.x + _tileSize.x * tileX, _point.y + _tileSize.y * tileY); if (isPixelPerfectRender(camera)) { @@ -281,7 +281,7 @@ class FlxBackdrop extends FlxSprite if (drawDirect) { // The distance between repeated sprites, in screen space - tileSize.set( + _tileSize.set( (frame.frame.width + spacing.x) * scale.x, (frame.frame.height + spacing.y) * scale.y ); @@ -323,7 +323,7 @@ class FlxBackdrop extends FlxSprite final origTileSizeX = (frameWidth + spacing.x) * scale.x; final left = modMin(bounds.right, origTileSizeX, viewMargins.left) - bounds.width; final right = modMax(bounds.left, origTileSizeX, viewMargins.right) + origTileSizeX; - tilesX = Math.round((right - left) / tileSize.x); + tilesX = Math.round((right - left) / _tileSize.x); _point.x = left + _point.x - bounds.x; } @@ -332,7 +332,7 @@ class FlxBackdrop extends FlxSprite final origTileSizeY = (frameHeight + spacing.y) * scale.y; final top = modMin(bounds.bottom, origTileSizeY, viewMargins.top) - bounds.height; final bottom = modMax(bounds.top, origTileSizeY, viewMargins.bottom) + origTileSizeY; - tilesY = Math.round((bottom - top) / tileSize.y); + tilesY = Math.round((bottom - top) / _tileSize.y); _point.y = top + _point.y - bounds.y; } viewMargins.put(); @@ -348,7 +348,7 @@ class FlxBackdrop extends FlxSprite { _tileMatrix.copyFrom(_matrix); - _tileMatrix.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY)); + _tileMatrix.translate(_point.x + (_tileSize.x * tileX), _point.y + (_tileSize.y * tileY)); if (isPixelPerfectRender(camera)) { From 902bff749029cd5589fca18a5fdec43a56656faa Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sat, 13 Apr 2024 10:26:18 -0500 Subject: [PATCH 3/3] revert certain changes, add tileSize.put calls --- flixel/addons/display/FlxBackdrop.hx | 81 ++++++++++++++-------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/flixel/addons/display/FlxBackdrop.hx b/flixel/addons/display/FlxBackdrop.hx index f969113b..fa12b5a9 100644 --- a/flixel/addons/display/FlxBackdrop.hx +++ b/flixel/addons/display/FlxBackdrop.hx @@ -49,10 +49,9 @@ class FlxBackdrop extends FlxSprite */ public var blitMode:BackdropBlitMode = AUTO; - var _tileSize:FlxPoint = FlxPoint.get(); - var _tileMatrix:FlxMatrix = new FlxMatrix(); var _blitOffset:FlxPoint = FlxPoint.get(); var _blitGraphic:FlxGraphic = null; + var _tileMatrix:FlxMatrix = new FlxMatrix(); var _prevDrawParams:BackdropDrawParams = { graphicKey:null, @@ -85,7 +84,6 @@ class FlxBackdrop extends FlxSprite override function destroy():Void { spacing = FlxDestroyUtil.put(spacing); - _tileSize = FlxDestroyUtil.put(_tileSize); _blitOffset = FlxDestroyUtil.put(_blitOffset); _blitGraphic = FlxDestroyUtil.destroy(_blitGraphic); _tileMatrix = null; @@ -204,9 +202,9 @@ class FlxBackdrop extends FlxSprite final frame = drawBlit ? _blitGraphic.imageFrame.frame : _frame; // The distance between repeated sprites, in screen space - _tileSize.set(frame.frame.width, frame.frame.height); + final tileSize = FlxPoint.get(frame.frame.width, frame.frame.height); if (drawDirect) - _tileSize.addPoint(spacing); + tileSize.addPoint(spacing); getScreenPosition(_point, camera).subtractPoint(offset); var tilesX = 1; @@ -216,18 +214,18 @@ class FlxBackdrop extends FlxSprite final viewMargins = camera.getViewMarginRect(); if (repeatAxes.x) { - final left = modMin(_point.x + frameWidth, _tileSize.x, viewMargins.left) - frameWidth; - final right = modMax(_point.x, _tileSize.x, viewMargins.right) + _tileSize.x; - tilesX = Math.round((right - left) / _tileSize.x); + final left = modMin(_point.x + frameWidth, tileSize.x, viewMargins.left) - frameWidth; + final right = modMax(_point.x, tileSize.x, viewMargins.right) + tileSize.x; + tilesX = Math.round((right - left) / tileSize.x); final origTileSizeX = frameWidth + spacing.x; _point.x = modMin(_point.x + frameWidth, origTileSizeX, viewMargins.left) - frameWidth; } if (repeatAxes.y) { - final top = modMin(_point.y + frameHeight, _tileSize.y, viewMargins.top) - frameHeight; - final bottom = modMax(_point.y, _tileSize.y, viewMargins.bottom) + _tileSize.y; - tilesY = Math.round((bottom - top) / _tileSize.y); + final top = modMin(_point.y + frameHeight, tileSize.y, viewMargins.top) - frameHeight; + final bottom = modMax(_point.y, tileSize.y, viewMargins.bottom) + tileSize.y; + tilesY = Math.round((bottom - top) / tileSize.y); final origTileSizeY = frameHeight + spacing.y; _point.y = modMin(_point.y + frameHeight, origTileSizeY, viewMargins.top) - frameHeight; } @@ -247,7 +245,7 @@ class FlxBackdrop extends FlxSprite for (tileY in 0...tilesY) { // _point.copyToFlash(_flashPoint); - _flashPoint.setTo(_point.x + _tileSize.x * tileX, _point.y + _tileSize.y * tileY); + _flashPoint.setTo(_point.x + tileSize.x * tileX, _point.y + tileSize.y * tileY); if (isPixelPerfectRender(camera)) { @@ -260,6 +258,7 @@ class FlxBackdrop extends FlxSprite } } + tileSize.put(); camera.buffer.unlock(); } @@ -277,11 +276,14 @@ class FlxBackdrop extends FlxSprite frame.prepareMatrix(_matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY()); _matrix.translate(-origin.x, -origin.y); - + + // The distance between repeated sprites, in screen space + final tileSize = FlxPoint.get(frame.frame.width, frame.frame.height); + if (drawDirect) { - // The distance between repeated sprites, in screen space - _tileSize.set( + tileSize.set + ( (frame.frame.width + spacing.x) * scale.x, (frame.frame.height + spacing.y) * scale.y ); @@ -296,10 +298,6 @@ class FlxBackdrop extends FlxSprite _matrix.rotateWithTrig(_cosAngle, _sinAngle); } } - else - { - _tileSize.set(frame.frame.width, frame.frame.height); - } var drawItem = null; if (FlxG.renderTile) @@ -316,39 +314,41 @@ class FlxBackdrop extends FlxSprite getScreenPosition(_point, camera).subtractPoint(offset); var tilesX = 1; var tilesY = 1; - final viewMargins = camera.getViewMarginRect(); - final bounds = getScreenBounds(camera); - if (repeatAxes.x) + if (repeatAxes != NONE) { - final origTileSizeX = (frameWidth + spacing.x) * scale.x; - final left = modMin(bounds.right, origTileSizeX, viewMargins.left) - bounds.width; - final right = modMax(bounds.left, origTileSizeX, viewMargins.right) + origTileSizeX; - tilesX = Math.round((right - left) / _tileSize.x); - _point.x = left + _point.x - bounds.x; - } + final viewMargins = camera.getViewMarginRect(); + final bounds = getScreenBounds(camera); + if (repeatAxes.x) + { + final origTileSizeX = (frameWidth + spacing.x) * scale.x; + final left = modMin(bounds.right, origTileSizeX, viewMargins.left) - bounds.width; + final right = modMax(bounds.left, origTileSizeX, viewMargins.right) + origTileSizeX; + tilesX = Math.round((right - left) / tileSize.x); + _point.x = left + _point.x - bounds.x; + } - if (repeatAxes.y) - { - final origTileSizeY = (frameHeight + spacing.y) * scale.y; - final top = modMin(bounds.bottom, origTileSizeY, viewMargins.top) - bounds.height; - final bottom = modMax(bounds.top, origTileSizeY, viewMargins.bottom) + origTileSizeY; - tilesY = Math.round((bottom - top) / _tileSize.y); - _point.y = top + _point.y - bounds.y; + if (repeatAxes.y) + { + final origTileSizeY = (frameHeight + spacing.y) * scale.y; + final top = modMin(bounds.bottom, origTileSizeY, viewMargins.top) - bounds.height; + final bottom = modMax(bounds.top, origTileSizeY, viewMargins.bottom) + origTileSizeY; + tilesY = Math.round((bottom - top) / tileSize.y); + _point.y = top + _point.y - bounds.y; + } + viewMargins.put(); + bounds.put(); } - viewMargins.put(); - bounds.put(); - _point.addPoint(origin); if (drawBlit) _point.addPoint(_blitOffset); - + for (tileX in 0...tilesX) { for (tileY in 0...tilesY) { _tileMatrix.copyFrom(_matrix); - _tileMatrix.translate(_point.x + (_tileSize.x * tileX), _point.y + (_tileSize.y * tileY)); + _tileMatrix.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY)); if (isPixelPerfectRender(camera)) { @@ -368,6 +368,7 @@ class FlxBackdrop extends FlxSprite } } + tileSize.put(); if (FlxG.renderBlit) camera.buffer.unlock(); }