dimanche 20 juin 2021

Phaser 3 drag event err while scrolling web page

I set a drag event on a gameobject. The hit area doesn't following the gameobject when I scroll the web page. What should I add in the code?

const dragTurret = this.scene.load.image(x, y, key);
        
    // 建立砲台拖曳事件
    dragTurret.setInteractive({ draggable: true })

    // 點選時新增砲台,讓原本的炮台物件變成可拖曳的物件
    .on(Phaser.Input.Events.GAMEOBJECT_DRAG_START, (point: any) => {
        this.setTurrent(key, x, y);
    })

    // 拖曳時物件跟隨鼠標
    .on('drag', (point: any) => {
        dragTurret.x = point.x;
        dragTurret.y = point.y;
    })

    // 結束拖曳時觸發放置炮台物件並將原本拖曳的物件摧毀
    .once('dragend', (point: any) => {
        dragTurret.destroy(); ...



Aucun commentaire:

Enregistrer un commentaire