Scale for PositionComponent (#892)

* Draft of PositionComponent.scale

* Use matrix transformations

* Update tests to take matrix transform into consideration

* Add tests for collision detection with scale

* Rename ScaleEffect to SizeEffect

* Use transform matrix to prepare canvas

* Fix scaledSizeCache

* Add changelog entries and docs

* Dartdoc on public access methods

* Update packages/flame/CHANGELOG.md

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>

* Move cache classes to own directory

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
This commit is contained in:
Lukas Klingsbo
2021-08-06 21:59:52 +02:00
committed by GitHub
parent 4860cac87f
commit 54fbd260bc
31 changed files with 497 additions and 150 deletions

View File

@ -50,12 +50,12 @@ abstract class MyCollidable extends PositionComponent
angleDelta = dt * rotationSpeed;
angle = (angle + angleDelta) % (2 * pi);
// Takes rotation into consideration (which topLeftPosition doesn't)
final topLeft = absoluteCenter - (size / 2);
if (topLeft.x + size.x < 0 ||
topLeft.y + size.y < 0 ||
topLeft.x > screenCollidable.size.x ||
topLeft.y > screenCollidable.size.y) {
final moduloSize = screenCollidable.size + size;
final topLeft = absoluteCenter - (scaledSize / 2);
if (topLeft.x + scaledSize.x < 0 ||
topLeft.y + scaledSize.y < 0 ||
topLeft.x > screenCollidable.scaledSize.x ||
topLeft.y > screenCollidable.scaledSize.y) {
final moduloSize = screenCollidable.scaledSize + scaledSize;
topLeftPosition = topLeftPosition % moduloSize;
}
}
@ -65,7 +65,7 @@ abstract class MyCollidable extends PositionComponent
super.render(canvas);
renderHitboxes(canvas, paint: _activePaint);
if (_isDragged) {
final localCenter = (size / 2).toOffset();
final localCenter = (scaledSize / 2).toOffset();
canvas.drawCircle(localCenter, 5, _activePaint);
}
}