mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user