gpt4 book ai didi

The getter 'velocity' isn't defined for the type 'JoystickComponent'(没有为类型“JoystickComponent”定义getter“velocity”)

转载 作者:bug小助手 更新时间:2023-10-22 16:38:52 34 4
gpt4 key购买 nike



I'm trying to make a Joystick

我正在试着做一个操纵杆


class JoystickPlayer extends SpriteComponent with HasGameRef {
JoystickPlayer(this.joystick)
: super(
anchor: Anchor.center,
size: Vector2.all(100.0),
);

/// Pixels/s
double maxSpeed = 300.0;

final JoystickComponent joystick;

@override
Future<void> onLoad() async {
sprite = await gameRef.loadSprite('layers/player.png');
position = gameRef.size / 2;
}

@override
void update(double dt) {
if (joystick.direction != JoystickDirection.idle) {
position.add(joystick.velocity * maxSpeed * dt);
angle = joystick.delta.screenAngle();
}
}
}

But I get a compile error:

但是我得到了一个编译错误:



The getter 'velocity' isn't defined for the type 'JoystickComponent'



I'm using Flame 1.8.2 link

我正在使用Flame 1.8.2链接


更多回答

As of Flame version 1.8.2, the JoystickComponent does not directly provide a joystick.velocity property. Instead, you can calculate the velocity by yourself. Based on the joystick's position changes.

从Flame 1.8.2版本开始,JoystickComponent没有直接提供joystick.velocity属性。相反,你可以自己计算速度。根据操纵手柄的位置变化。

优秀答案推荐

The JoystickComponent doesn't have a velocity field, it does have a relativeDelta field that you can use though, which is the percentage and direction that the knob is from the center of the joystick to the edge.

操纵杆组件没有速度场,但它有一个相对的德尔塔场,你可以使用,这是旋钮从操纵杆中心到边缘的百分比和方向。


So for example if you pull the knob completely to the right the relativeDelta would be Vector2(1.0, 0.0), and completely to the left, Vector2(-1.0, 0.0).

因此,例如,如果将旋钮完全向右拉动,则相对德尔塔将为Vector2(1.0,0.0),而完全向左拉动,则为Vector 2(-1.0,0.0)。


So you can use it quite similarly to how you tried:

因此,您可以使用与您尝试的方式非常相似的方法:


  @override
void update(double dt) {
if (!joystick.direction != JoystickDirection.idle) {
position.add(joystick.relativeDelta * maxSpeed * dt);
angle = joystick.delta.screenAngle();
}
}

更多回答

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com