Commits

abrie  committed 6a0819c

implement rudimentary system for z-layers

  • Participants
  • Parent commits 4a0cb29

Comments (0)

Files changed (1)

         "green": {r:0,g:255,b:0}
     }
 
+    var layers = {
+        1:[],2:[],3:[]
+    }
+
+    var queueSprite = function(layer, sprite) {
+        layers[layer].push(sprite);
+    }
+
+    var addQueuedSprites = function() {
+        var forEach = function(array) {
+            array.forEach( function(sprite) {
+                display2d.stage.addChild(sprite);
+            });
+            array.length = 0;
+        }
+
+        forEach(layers[1]);
+        forEach(layers[2]);
+        forEach(layers[3]);
+    }
+
     var createBall = function(ballType,x,y) {
         var colors = ballColors[ballType];
         var radius = 0.50;
             },
             sprite:createBallSprite(radius, colors.r,colors.g,colors.b)
         });
-        display2d.stage.addChild( ball.body.userData.sprite );
+        queueSprite(2,ball.body.userData.sprite);
         actors.push( ball );
         return ball;
     }
             },
             sprite:createWarpHoleSprite(warpHoleSpriteFiles[id]),
         });
-        display2d.stage.addChild( warpHole.body.userData.sprite );
+        queueSprite(3, warpHole.body.userData.sprite );
         warpHole.body.userData.sprite.gotoAndPlay("closed");
         actors.push( warpHole );
         warpHoles[ warpHole.body.userData.attributes.warpHoleId ] = warpHole;
         var viewCenter = display2d.viewCenterPixel();
         sprite.x = centerx*display2d.PTM + viewCenter.x;
         sprite.y = -centery*display2d.PTM + viewCenter.y;
-        display2d.stage.addChild( sprite );
+        queueSprite( 1, sprite );
     }
 
     var createWallSprite = function(horizontal,vertical) {
         var v = (vertical/2)*display2d.PTM;
         g.moveTo(h,v);
         g.lineTo(-h,-v);
-        console.log(horizontal,vertical,h,v,-h,-v);
         var shape = new createjs.Shape(g);
         shape.regX = 0;
         shape.regY = 0;
         var viewCenter = display2d.viewCenterPixel();
         sprite.x = centerx*display2d.PTM + viewCenter.x;
         sprite.y = -centery*display2d.PTM + viewCenter.y;
-        display2d.stage.addChild( sprite );
+        queueSprite( 1, sprite );
     }
 
     var world = undefined;
                 createWarpHole( object.warpHoleId, object.x, object.y );
             }
         });
+        addQueuedSprites();
     }
 
     var clearWorld = function() {