iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 12
0
Modern Web

Phaser 幫我撐個 30 天系列 第 12

Day 12:Drag

》Drag
今天我們用昨天一樣的素材,要讓 man 可以拖曳,當然目前這個小範例是不需要拖曳,但是我們假如以後用到的話,大概就知道方向。例如你可以用該方式,先把障礙物或敵人放到你想要得位置,這樣就不用一直測你想要的位置是哪個地方了。

》Javascript 內容

scene.create = function() {
    .....
     // 設定互動
    this.man = this.add.sprite(50, 255, 'man', 0).setInteractive()

    this.input.setDraggable(this.man)

    // 偵聽 drag
        this.input.on('drag', function(pointer, gameObj, dragX, dragY) {
        gameObj.x = dragX
        gameObj.y = dragY
    })
}

》結論
今天把 man 物件拿來實驗,也可以試著把 bg 物件拖曳看看。
https://ithelp.ithome.com.tw/upload/images/20181027/201116178CyK0x83po.png
https://ithelp.ithome.com.tw/upload/images/20181027/20111617wvf39YEHov.png


今天就先到這裡,我們明天見。


上一篇
Day 11:Sprite sheet
下一篇
Tween [ 1 / 2 ]
系列文
Phaser 幫我撐個 30 天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言