I am making a simple basketball shoot game in Flutter Flame and am using Box2D for the physics. I am trying to make the ball a BodyComponent but for some reason, when I try to not render the BodyComponent (only trying to see the sprite), it keep showing. Here is the code:
import 'dart:async';
import 'dart:ui';
import 'package:bball_blast/bballBlast.dart';
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
class Ball extends BodyComponent {
@override
final bballBlast game;
@override
final Vector2 position;
Ball(this.game, this.position) : super (
renderBody: false
);
@override
Future<void> onLoad() async {
await super.onLoad();
renderBody=false;
add(
SpriteComponent(
sprite: await game.loadSprite('ball.png'),
size: Vector2 (150, 150),
anchor: Anchor.center,
position: Vector2(100,100)
),
);
}
@override
Body createBody() {
final shape = CircleShape()..radius = 125; // Radius is half the size
final fixtureDef =
FixtureDef(shape, friction: 0.5);
final bodyDef = BodyDef(position: Vector2(20, 5), type: BodyType.dynamic);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
any help would be greatly appreciated.