-
Hello,
|
Beta Was this translation helpful? Give feedback.
Answered by
tenpaMk2
Jan 23, 2023
Replies: 1 comment 1 reply
-
Hi, @KrzyZyb . constructor(private engine: Engine) {
this.eventPubSuber = new Actor();
let dragUI: ScreenElement;
engine.input.pointers.primary.on("down", (event: PointerEvent): void => {
if (dragUI) dragUI.kill(); // if you right-click, this process is needed.
dragUI = new ScreenElement({
pos: event.screenPos,
});
engine.add(dragUI);
engine.input.pointers.primary.on("move", (event: PointerEvent): void => {
const canvas = new Canvas({
width: engine.drawWidth,
height: 32, // must be 2^n
draw: (ctx: CanvasRenderingContext2D) => {
ctx.fillStyle = "red";
const length = event.screenPos.distance(dragUI.pos);
ctx.fillRect(0, 0, length, 32);
},
});
dragUI.graphics.use(canvas);
dragUI.anchor = new Vector(0, 0.5);
const rotation = event.screenPos.sub(dragUI.pos).toAngle();
dragUI.rotation = rotation;
});
});
engine.input.pointers.primary.on("up", (event: PointerEvent): void => {
if (!dragUI) return;
dragUI.kill();
engine.input.pointers.primary.off("move");
this.eventPubSuber.emit(
"brace",
new BracingEvent(
event.screenPos.distance(dragUI.pos),
event.screenPos.sub(dragUI.pos).toAngle() + Math.PI
)
);
});
} This logic means ↓
Here is screenshot. I hope this helps you❗ |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
KrzyZyb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @KrzyZyb .
I have created a similar logic, but maybe it does not match perfectly your case.
See my bowman example:
tap-ui.ts
.