Permalink
Browse files

Fixing localGlobal bug in ItemScroller.

  • Loading branch information...
1 parent 003e53f commit ffe9ac47d57ce7dd1d3d1d5aae7a429d9844733a @presstube committed Oct 26, 2011
Showing with 29 additions and 13 deletions.
  1. +2 −2 src/hunted/HuntedApp.js
  2. +27 −11 src/hunted/ItemScroller.js
@@ -6,7 +6,7 @@
gameState = "GAME_OVER",
numChasersToSpawn = 1,
paused = false,
- wrapRadius = 4000,
+ wrapRadius = 3000,
chasers = [],
projectiles = [],
canvas = document.getElementById("canvas"),
@@ -75,7 +75,7 @@
scaleStage.addChild(trackingStage);
scaleStage.addChildAt(parallaxScroller, 0);
- scaleStage.setScaleMultiplier(1);
+ // scaleStage.setScaleMultiplier(1);
trackingStage.addChild(itemScroller);
trackingStage.addChild(ship);
@@ -47,17 +47,33 @@
this.tick = function() {
globalScaleStageCenter = scaleStage.localToGlobal(0, 0);
direction = PTUtils.angleRadians(trackingStage.getAmountToMove(), new Point() );
- _.each(items, function(item) {
- var globalItemCenter = item.localToGlobal(0, 0);
- var distanceFromCenter = PTUtils.distance(globalItemCenter, globalScaleStageCenter);
- if ( distanceFromCenter > wrapRadius ) {
- var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
- var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
- var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
- item.x = localScaleStageCenter.x + respawnPoint.x;
- item.y = localScaleStageCenter.y + respawnPoint.y;
- }
- });
+
+ for (var i = 0; i < items.length; i++) {
+ var item = items[i];
+ var globalItemCenter = item.localToGlobal(0, 0);
+ var localItemPos = scaleStage.globalToLocal(globalItemCenter.x, globalItemCenter.y);
+ // if (i === 0) { console.log("localItemPos: " + localItemPos); }
+ var distanceFromCenter = PTUtils.distance(localItemPos, new Point());
+ if ( distanceFromCenter > wrapRadius ) {
+ var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
+ var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
+ var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
+ item.x = localScaleStageCenter.x + respawnPoint.x;
+ item.y = localScaleStageCenter.y + respawnPoint.y;
+ }
+ }
+
+ // _.each(items, function(item) {
+ // var globalItemCenter = item.localToGlobal(0, 0);
+ // var distanceFromCenter = PTUtils.distance(globalItemCenter, globalScaleStageCenter);
+ // if ( distanceFromCenter > wrapRadius ) {
+ // var localScaleStageCenter = that.globalToLocal(globalScaleStageCenter.x, globalScaleStageCenter.y);
+ // var respawnAngleRadians = PTUtils.getOppositeAngleRadians(direction);
+ // var respawnPoint = PTUtils.polarRadians(wrapRadius, respawnAngleRadians);
+ // item.x = localScaleStageCenter.x + respawnPoint.x;
+ // item.y = localScaleStageCenter.y + respawnPoint.y;
+ // }
+ // });
};
};

0 comments on commit ffe9ac4

Please sign in to comment.