2018-08-09

var MvCvsSprite = function(ui, asset, sourceX, sourceY, sourceWidth, sourceHeight, x, y, width, height) {

? ? DisplayObject.bind(this)(ui, x, y, width, height);

? ? this.asset = asset;

? ? this.sourceX = sourceX

? ? this.sourceY = sourceY

? ? this.sourceWidth = sourceWidth;

? ? this.sourceHeight = sourceHeight;

? ? this.startY = undefined;

? ? this.moveY = 0;

? ? this.onMoveThis = this.onMove.bind(this);

? ? this.onUpThis = this.onUp.bind(this);? ?

????this.onClick(() => {

? ? ? ? console.info('You got me!');

? ? ? ? window.addEventListener('mousemove', this.onMoveThis);

? ? ? ? window.addEventListener('mouseup',this.onUpThis);

? ? });

};

MvCvsSprite.prototype = Object.create(DisplayObject.prototype);

MvCvsSprite.prototype.draw = function(context, x, y, width, height) {

? ? context.drawImage(this.asset, this.sourceX, this.sourceY, this.sourceWidth, this.sourceHeight, x, y, width, height);

};

// wx.onTouchMove(

MvCvsSprite.prototype.onMove = function (e) {

? ? var canvasPos = {x:0, y:0};

? ? canvasPos = ui.windowToUISpace(e.clientX, e.clientY)

? ? if (this.startY === undefined) {

? ? ? ? this.startY = canvasPos.y + this.moveY;

? ? }

? ? this.moveY = this.startY - canvasPos.y;

? ? console.log(this.moveY);

? ? this.sourceY = this.moveY;

? ? ui.shouldReDraw = true;

}

// wx.onTouchEnd(

MvCvsSprite.prototype.onUp = function (e) {

? ? this.startY = undefined;

? ? if (this.moveY < 0) { // 到頂

? ? ? ? this.moveY = 0;

? ? } else if (this.moveY > this.asset.height - this.height) { // 到底

? ? ? ? this.moveY = this.asset.height - this.height;

? ? }

? ? console.log(this.moveY);

? ? this.sourceY = this.moveY;

? ? ui.shouldReDraw = true;

? ? window.removeEventListener('mousemove', this.onMoveThis);

? ? window.removeEventListener('mouseup', this.onUpThis);

};

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些閱讀 2,136評論 0 2
  • 找到fullcalendar.js, 找到代碼為 isRTL:false,這句話 輸入以下幾句 monthName...
    迷你小小白閱讀 1,854評論 0 1
  • 初等數(shù)學(xué)2300年之重大錯誤:將無窮多各異點集誤為同一集 ——讓中學(xué)生也能一下子認(rèn)識3000年都無人能識的直線段 ...
    hxl268閱讀 593評論 0 0
  • 1,換行 2,html圖像通過標(biāo)簽 來定義 3,class為html 元素定義一個或者多個類名 (classNam...
    滔滔逐浪閱讀 198評論 0 0
  • 曉曉是我的初戀女友,也是我的前任女友,更是我曾經(jīng)認(rèn)定會攜手一生的女人。如今,她結(jié)婚了,老公不是我?;楹蟮乃龝r常打來...
    三湘漣漪閱讀 29,762評論 317 1,019

友情鏈接更多精彩內(nèi)容