程式码如下


JavaScript

const fill_rect=hmUI.createWidget(hmUI.widget.FILL_RECT, {

       x: 0,
       y: 0,
       w: 192 * 4, //768
       h: 490,
       radius: 20,
       color: 0x5BA33D
      })
let canmove=true 
fill_rect.addEventListener(hmUI.event.CLICK_DOWN, (info) => {
       if(canmove){UI_move_for_easeInOutQuart(oTo, {
        x: info.x,
        y: info.y
       })
       canmove=false
       }
      })
      let oToxy = {
       x: 70,
       y: 150
      }
      let oTo = hmUI.createWidget(hmUI.widget.TEXT, {
       x: oToxy.x,
       y: oToxy.y,
       w: 70,
       h: 22,
       color: "0x000000",
       text_size: 20,
       text_style: hmUI.text_style.WRAP,
       text: "史莱姆"
      });
      function easeInOutQuart(x) {
       return x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2;
      }
      function UI_move_for_easeInOutQuart(UI, xy) {
      let wansixy = {
       x: oToxy.x,
       y: oToxy.y
      }
       let isfoo = !(Math.abs(oToxy.y-xy.y)===oToxy.y-xy.y)
       let moveend = Math.abs(oToxy.y-xy.y)
       let moveing = 0

       let timers = timer.createTimer(15, 20, (function(e) {
        moveing += 20 //+10
        let moveN = (easeInOutQuart((moveing / moveend)) * moveend)

    UI.setProperty(hmUI.prop.MORE, {
         x: 0,
         y: (isfoo ? oToxy.y = xy.y - moveN : oToxy.y = xy.y - moveN),
        })
       if (isfoo ? (oToxy.y <= xy.y) : (oToxy.y >= xy.y) ) {
       canmove=true
         timer.stopTimer(timers)
        }
       }))
      }

共有 2 則留言

好了

      const fill_rect = hmUI.createWidget(hmUI.widget.FILL_RECT, {
       x: 0,
       y: 0,
       w: 192 * 4, //768
       h: 490,
       radius: 20,
       color: 0x5BA33D
      })
let canmove=true
      fill_rect.addEventListener(hmUI.event.CLICK_DOWN, (info) => {
       if(canmove){UI_move_for_easeInOutQuart(oTo, {
        x: info.x,
        y: info.y
       })
       canmove=false
       }
      })
      let oToxy = {
       x: 70,
       y: 150
      }
      let oTo = hmUI.createWidget(hmUI.widget.TEXT, {
       x: oToxy.x,
       y: oToxy.y,
       w: 70,
       h: 25,
       color: "0x000000",
       text_size: 20,
       text_style: hmUI.text_style.WRAP,
       text: "史莱姆"
      });

      function easeInOutQuad(t, b, c, d) {
    t /= d/2;
    if (t < 1) return c/2*t*t + b;
    t--;
    return -c/2 * (t*(t-2) - 1) + b;
}
//easeInOutQuad(count, wansixy.y, moveend, 20)//0.1*20=2秒
/*
t是當前時間
b是起始值
c是值的變化
d是持續時間
*/
      function UI_move_for_easeInOutQuart(UI, xy) {
      let wansixy = {
       x: oToxy.x,
       y: oToxy.y
      }
      let count=0
       let moveendy = xy.y-wansixy.y
       let moveendx = xy.x-wansixy.x
       let timers = timer.createTimer(15, 10, (function(e) {
       count++;
        UI.setProperty(hmUI.prop.MORE, {
         x: (oToxy.x=easeInOutQuad(count, wansixy.x, moveendx, 20)),
         y: (oToxy.y=easeInOutQuad(count, wansixy.y, moveendy, 20)),
        })
       if (count>=20) {
       canmove=true
         timer.stopTimer(timers)
        }
       }))

      }


按讚的人:

缺乏上下文,看不太懂問題是什麼

不過,你應該已經自己解決了吧,那就好