pixi.js 拖拽功能

        // 加载狐狸
        let fox = pixiTexture.from('https://img.alicdn.com/imgextra/i1/39767794/O1CN01t13qMt27RhbmdFfsh_!!39767794.png')
        let firfox = new pixiSprite(fox)
        application.stage.addChild(firfox)

        //移动狐狸
        let flag = false
        firfox.interactive = true
        firfox.buttonMode = true
        firfox.anchor.set(0.5) //设置中心点
        firfox.x = application.screen.width / 2 //狐狸初始位置
        firfox.y = application.screen.height - 300
        // 滑动狐狸
        firfox.on('touchstart', () => {
          flag = true
        })
          .on('touchmove', (e) => {
            if (flag) {
              if (e.data.global.x > 115 / 2 && e.data.global.x < application.screen.width - 115 / 2 && e.data.global.y > 111 / 2 && e.data.global.y < application.screen.height - 111 / 2) {
                firfox.x = e.data.global.x
                firfox.y = e.data.global.y
              } else {
              }
            }
          })
          .on('touchend', () => {
            flag = false
          })
          .on('touchendoutside', () => {
            flag = false
          })

版权声明:本文为weixin_44387746原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。