Skip to content

Commit

Permalink
impl: coordinate_mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
gnlow committed Dec 29, 2023
1 parent d11b395 commit 1f87aaf
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class Entry {
timer = new Timer()

isClicked = false
mouseX = 0
mouseY = 0

constructor(project: Project) {
this.gainNode.connect(this.audioContext.destination)
Expand Down Expand Up @@ -178,16 +180,27 @@ export class Entry {
backgroundColor: "#fff",
resolution: 4
})
parent.appendChild(this.renderer.canvas)

parent.addEventListener("pointerdown", () => {
const canvas = this.renderer.canvas
console.log(this.renderer.events.features)

parent.appendChild(canvas)

canvas.addEventListener("pointerdown", () => {
this.isClicked = true
this.emit("pointerdown")
})
parent.addEventListener("pointerup", () => {
canvas.addEventListener("pointerup", () => {
this.isClicked = false
this.emit("pointerup")
})
Object.values(this.scenes).map(scene => {
scene.eventMode = "static"
scene.addEventListener("globalpointermove", e => {
this.mouseX = e.globalX - 240
this.mouseY = 135 - e.globalY
})
})

const loop = () => {
this.render()
Expand Down Expand Up @@ -719,6 +732,10 @@ export class Entry {
calc_rand(a: number, b: number) {
return Math.random() * (b - a) + a
}
coordinate_mouse(type: "x" | "y") {
if (type == "x") return this.mouseX
if (type == "y") return this.mouseY
}
coordinate_object(
targetId: string,
type:
Expand Down

0 comments on commit 1f87aaf

Please sign in to comment.