Browse Source

[ts] Fixed all demos with handles. Handles can no longer be dragged outside the canvas.

badlogic 6 năm trước cách đây
mục cha
commit
5ebb3db8b6

+ 5 - 2
spine-ts/webgl/demos/additiveblending.js

@@ -88,12 +88,15 @@ var additiveBlendingDemo = function(canvas, bgColor) {
 	function calculateBlend (x, y, isPageCoords) {
 		if (isPageCoords) {
 			var canvasBounds = canvas.getBoundingClientRect();
-			console.log(canvasBounds.x + ", " + canvasBounds.y + ", " + x + ", " + y);
 			x = Math.max(0, Math.min(canvasBounds.width, x - canvasBounds.x));
 			y = Math.max(0, Math.min(canvasBounds.height, y - canvasBounds.y));
 		}
 		x = x / canvas.width;
 		y = y / canvas.height;
+		if (x > 1) x = 1;
+		if (x < 0) x = 0;
+		if (y > 1) y = 1;
+		if (y < 0) y = 0;
 		left.alpha = (Math.max(x, 0.5) - 0.5) * 2;
 		right.alpha = (0.5 - Math.min(x, 0.5)) * 2;
 		up.alpha = (0.5 - Math.min(y, 0.5)) * 2;
@@ -119,7 +122,7 @@ var additiveBlendingDemo = function(canvas, bgColor) {
 					dragging = false;
 				},
 				dragged: function(x, y) {
-					if (dragging) {
+					if (dragging && x > 0 && x < canvas.width && y > 0 && y < canvas.height) {
 						renderer.camera.screenToWorld(coords.set(x, y, 0), canvas.width, canvas.height);
 						handle.x = coords.x;
 						handle.y = coords.y;

+ 1 - 1
spine-ts/webgl/demos/hoverboard.js

@@ -117,7 +117,7 @@ var hoverboardDemo = function(canvas, bgColor) {
 				target = null;
 			},
 			dragged: function(x, y) {
-				if (target != null) {
+				if (target != null && x > 0 && x < canvas.width && y > 0 && y < canvas.height) {
 					renderer.camera.screenToWorld(coords.set(x, y, 0), canvas.width, canvas.height);
 					if (target.parent !== null) {
 						target.parent.worldToLocal(temp2.set(coords.x, coords.y));

+ 1 - 1
spine-ts/webgl/demos/stretchyman.js

@@ -91,7 +91,7 @@ var stretchymanDemo = function(canvas, bgColor) {
 				target = null;
 			},
 			dragged: function(x, y) {
-				if (target != null) {
+				if (target != null && x > 0 && x < canvas.width && y > 0 && y < canvas.height) {
 					renderer.camera.screenToWorld(coords.set(x, y, 0), canvas.width, canvas.height);
 					if (target.parent !== null)
 						target.parent.worldToLocal(temp2.set(coords.x - skeleton.x, coords.y - skeleton.y));

+ 1 - 1
spine-ts/webgl/demos/transforms.js

@@ -110,7 +110,7 @@ var transformsDemo = function(canvas, bgColor) {
 				target = null;
 			},
 			dragged: function(x, y) {
-				if (target != null) {
+				if (target != null && x > 0 && x < canvas.width && y > 0 && y < canvas.height) {
 					if (target === rotateHandle) {
 						var rotation = getRotation(x, y);
 						var delta = rotation - lastRotation;

+ 1 - 1
spine-ts/webgl/demos/vine.js

@@ -108,7 +108,7 @@ var vineDemo = function(canvas, bgColor) {
 				target = null;
 			},
 			dragged: function(x, y) {
-				if (target != null) {
+				if (target != null && x > 0 && x < canvas.width && y > 0 && y < canvas.height) {
 					renderer.camera.screenToWorld(coords.set(x, y, 0), canvas.width, canvas.height);
 					if (target.parent !== null) {
 						target.parent.worldToLocal(temp2.set(coords.x - skeleton.x, coords.y - skeleton.y));