while looking for documentation, I'm really confused, since in https://docs.flame-engine.org/1.0.0/components.html?highlight=bodycomponent#spritebodycomponent SpriteBodyComponent is still using, but in
flame_forge2d: 0.12.3
flame: 1.4.0
I can't find this SpriteBodyComponent.
Because Im following a tutorial and the code looks like this:
class Ball extends SpriteBodyComponent {
...
}
But since I can not find SpriteBodyComponent, my code is like this:
class Ball extends BodyComponent{
...
}
And then tutorial is using Vector2 size
from SpriteBodyComponent, and I have no idea what I can do.. since in official documentation SpriteBodyComponent still exists, but what I find from flame flame package is SpriteComponent
but what I want to find should be from flame_forge2d something like SpriteBodyComponent, and if I use such code:
class Ball extends SpriteBodyComponent{
...
}
I got error Mixin can only be applied to class.
and I can not find it in flame-forge2d package either.
thanks in advance for your help!
You are looking at the documentation for Flame 1.0.0
, the latest version currently is 1.4.0
as you have found out, you can change version of the docs in the upper right corner.
These are the latest flame_forge2d
docs:
https://docs.flame-engine.org/1.4.0/flame_forge2d/forge2d.html
But to answer your question, yes, SpriteBodyComponent
has been deprecated.
Now instead you add a SpriteComponent
as a child to a BodyComponent
, for example like this:
class Pizza extends BodyComponent {
final Vector2 position;
final Vector2 size;
Pizza(
this.position,
this.size,
);
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite('pizza.png');
renderBody = false;
add(
SpriteComponent(
sprite: sprite,
size: size,
anchor: Anchor.center,
),
);
}
@override
Body createBody() {
// Create your body
}
}