flame
flame copied to clipboard
CircleHitbox doesn't scale
What happened?
When scaling a CircleHitbox, the debug lines make it look like it scaled correctly, but collisions don't register in the bounds because the hit box didn't scale.
What do you expect?
CircleHitbox should scale.
How can we reproduce this?
No response
What steps should take to fix this?
No response
Do have an example of where the bug occurs?
void main() {
runApp(
const MaterialApp(
home: GameWidget.controlled(
gameFactory: _MyGame.new,
),
),
);
}
class _MyGame extends FlameGame with HasCollisionDetection {
@override
Future<void> onLoad() async {
camera = CameraComponent.withFixedResolution(width: 640, height: 360);
await world.add(
_MyCircleComponent(BasicPalette.white.color.withAlpha(100),
BasicPalette.red.color.withAlpha(100),
radius: 20, anchor: Anchor.center)
..add(
MoveByEffect(
Vector2(50, 0),
EffectController(
duration: 2,
alternate: true,
infinite: true,
),
),
),
);
await world.add(
_MyCircleComponent(
BasicPalette.green.color.withAlpha(100),
BasicPalette.blue.color.withAlpha(100),
radius: 20,
anchor: Anchor.center,
position: Vector2(80, 0),
)..add(
ScaleEffect.by(
Vector2.all(2),
EffectController(
duration: 2,
alternate: true,
infinite: true,
),
),
),
);
}
}
class _MyCircleComponent extends CircleComponent with CollisionCallbacks {
final Color color;
final Color hitColor;
_MyCircleComponent(this.color, this.hitColor,
{super.position, super.radius, super.anchor});
@override
Future<void> onLoad() async {
super.onLoad();
paint.color = color;
await add(CircleHitbox()..debugMode = true);
}
@override
void onCollisionStart(
Set<Vector2> intersectionPoints, PositionComponent other) {
paint.color = hitColor;
super.onCollisionStart(intersectionPoints, other);
}
@override
void onCollisionEnd(PositionComponent other) {
paint.color = color;
super.onCollisionEnd(other);
}
}
Relevant log output
Execute in a terminal and put output into the code block below
Output of: flutter doctor -v
Affected platforms
All
Other information
No response
Are you interested in working on a PR for this?
- [ ] I want to work on this