Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

增加对点击事件的处理 #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</canvas>
</div>
<script type="text/javascript" src="device.min.js"></script>
<script type="text/javascript" src="bundle.js?64fe0900cd19ddfbda5b"></script></body>
<script type="text/javascript" src="bundle.js?0f7f527630fd90639e82"></script></body>
</html>
<!-- loadlive2d("live2dcanvas", "../assets/name/name.model.json", 0.5); -->
34 changes: 29 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,38 @@ function modelTurnHead(event)
let vy = transformViewY(target.y - rect.top);

if (LAppDefine.DEBUG_MOUSE_LOG)
console.log("onMouseDown device( x:" + event.clientX + " y:" + event.clientY + " ) view( x:" + vx + " y:" + vy + ")");
console.log("onMouseMove device( x:" + event.clientX + " y:" + event.clientY + " ) view( x:" + vx + " y:" + vy + ")");

lastMouseX = sx;
lastMouseY = sy;

dragMgr.setPoint(vx, vy);
dragMgr.setPoint(vx, vy);
}

function modelTapEvent(event)
{
drag = true;

let rect = canvas.getBoundingClientRect();

let sx = transformScreenX(event.clientX - rect.left);
let sy = transformScreenY(event.clientY - rect.top);
let target = transformRect({
x: rect.left + rect.width / 2,
y: rect.top + rect.height * head_pos
}, {
x: event.clientX,
y: event.clientY
}, rect)
let vx = transformViewX(target.x - rect.left);
let vy = transformViewY(target.y - rect.top);

if (LAppDefine.DEBUG_MOUSE_LOG)
console.log("onMouseDown device( x:" + event.clientX + " y:" + event.clientY + " ) view( x:" + vx + " y:" + vy + ")");

lastMouseX = sx;
lastMouseY = sy;

live2DMgr.tapEvent(vx, vy);
}

Expand Down Expand Up @@ -358,8 +383,7 @@ function mouseEvent(e)
// if (e.wheelDelta > 0) modelScaling(1.1);
// else modelScaling(0.9);
} else if (e.type == "mousedown") {
if("button" in e && e.button != 0) return;
// modelTurnHead(e);
modelTapEvent(e);
} else if (e.type == "mousemove") {
modelTurnHead(e);
} else if (e.type == "mouseup") {
Expand All @@ -374,7 +398,7 @@ function touchEvent(e)
{
var touch = e.touches[0];
if (e.type == "touchstart") {
if (e.touches.length == 1) modelTurnHead(touch);
if (e.touches.length == 1) modelTapEvent(touch);
// onClick(touch);
} else if (e.type == "touchmove") {
followPointer(touch);
Expand Down