Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixing localGlobal bug in ItemScroller.

  • Loading branch information...
commit ffe9ac47d57ce7dd1d3d1d5aae7a429d9844733a 1 parent 003e53f
James Paterson authored
4  src/hunted/HuntedApp.js
@@ -6,7 +6,7 @@
6 6
 			gameState = "GAME_OVER",
7 7
 			numChasersToSpawn = 1,
8 8
 			paused = false,
9  
-			wrapRadius = 4000,
  9
+			wrapRadius = 3000,
10 10
 			chasers = [],
11 11
 			projectiles = [],
12 12
 			canvas = document.getElementById("canvas"),
@@ -75,7 +75,7 @@
75 75
 
76 76
 		scaleStage.addChild(trackingStage);
77 77
 		scaleStage.addChildAt(parallaxScroller, 0);
78  
-		scaleStage.setScaleMultiplier(1);
  78
+		// scaleStage.setScaleMultiplier(1);
79 79
 
80 80
 		trackingStage.addChild(itemScroller);
81 81
 		trackingStage.addChild(ship);
38  src/hunted/ItemScroller.js
@@ -47,17 +47,33 @@
47 47
 		this.tick = function() {
48 48
 			globalScaleStageCenter = scaleStage.localToGlobal(0, 0);
49 49
 			direction = PTUtils.angleRadians(trackingStage.getAmountToMove(), new Point() );
50  
-			_.each(items, function(item) {
51  
-					var globalItemCenter = item.localToGlobal(0, 0);
52  
-					var distanceFromCenter = PTUtils.distance(globalItemCenter, globalScaleStageCenter);
53  
-					if ( distanceFromCenter > wrapRadius ) {
54  
-						var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
55  
-						var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
56  
-						var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
57  
-						item.x = localScaleStageCenter.x + respawnPoint.x;
58  
-						item.y = localScaleStageCenter.y + respawnPoint.y;
59  
-					}
60  
-			});
  50
+
  51
+			for (var i = 0; i < items.length; i++) {
  52
+				var item = items[i];
  53
+				var globalItemCenter = item.localToGlobal(0, 0);
  54
+				var localItemPos = scaleStage.globalToLocal(globalItemCenter.x, globalItemCenter.y);
  55
+				// if (i === 0) { console.log("localItemPos: " + localItemPos); }
  56
+				var distanceFromCenter = PTUtils.distance(localItemPos, new Point());
  57
+				if ( distanceFromCenter > wrapRadius ) {
  58
+					var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
  59
+					var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
  60
+					var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
  61
+					item.x = localScaleStageCenter.x + respawnPoint.x;
  62
+					item.y = localScaleStageCenter.y + respawnPoint.y;
  63
+				}
  64
+			}
  65
+
  66
+			// _.each(items, function(item) {
  67
+			// 		var globalItemCenter = item.localToGlobal(0, 0);
  68
+			// 		var distanceFromCenter = PTUtils.distance(globalItemCenter, globalScaleStageCenter);
  69
+			// 		if ( distanceFromCenter > wrapRadius ) {
  70
+			// 			var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
  71
+			// 			var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
  72
+			// 			var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
  73
+			// 			item.x = localScaleStageCenter.x + respawnPoint.x;
  74
+			// 			item.y = localScaleStageCenter.y + respawnPoint.y;
  75
+			// 		}
  76
+			// });
61 77
 		};
62 78
 	};
63 79
 

0 notes on commit ffe9ac4

Please sign in to comment.
Something went wrong with that request. Please try again.