-
Hello guys, I'm making a simple brick breaker for fun with flame + forge2d. I managed to get the platform to follow the mouse move on web but the way I did it seems too complicated. My platform is just a component that draw a rectangle (BouncerComponent), and when the cursor move I just update the position: final gameSize = Vector2(1920, 1080);
@override
void onMouseMove(PointerHoverInfo info) {
target = info.eventPosition.game;
final bouncerComponent = cameraWorld.firstChild<BouncerComponent>()!;
// I only move along the x axis, -50 is just half the width of the platform
bouncerComponent.position = Vector2(
info.eventPosition.game.x / canvasSize.x * gameSize.x - 50,
bouncerComponent.position.y,
);
} I tried the screenToWorld but doesn't work. I also tried to use viewport and widget position from the cursor event but all values are the same. The only way I managed to get it work properly is to get a ratio of the cursor relative to the screen and multiply the game size. Also I tested to draw directly from render method and it works without any conversion. Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
A simpler way to do this would be to use a There is a mouse joint example here: https://examples.flame-engine.org/#/flame_forge2d%2Fjoints_MouseJoint |
Beta Was this translation helpful? Give feedback.
-
Thanks! I prefer this way. |
Beta Was this translation helpful? Give feedback.
A simpler way to do this would be to use a
MouseJoint
, have you tried that?There is a mouse joint example here: https://examples.flame-engine.org/#/flame_forge2d%2Fjoints_MouseJoint