我正在尝试移动 Vector2 的 x 位置,正在调用更新,x 值正在更改但白色方形组件没有移动,我错过了什么?
我正在使用火焰 1.0.0-releasecandidate.11。
import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/palette.dart';
class PlayerComponent extends PositionComponent {
static const squareSize = 128.0;
static Paint white = BasicPalette.white.paint();
@override
void render(Canvas canvas) {
canvas.drawRect(size.toRect(), white);
super.render(canvas);
}
@override
void update(double dt) {
x += 10 * dt;
print(x);
super.update(dt);
}
@override
void onMount() {
super.onMount();
size.setValues(squareSize, squareSize);
anchor = Anchor.center;
}
}
class AnimalVillageGame extends BaseGame {
@override
Future<void> onLoad() async {
add(PlayerComponent()
..x = 100
..y = 100
);
}
}