title: Getting the stage to follow the players Y axis. (Flash As3)
body: <p>I'll try my best to give you as much detail as I can.</p>
  
  <p>I have created a platform game and I have already implemented movement and collision.</p>
  
  <p>My game Loop runs this (I only have one eventListener)</p>
  
  <pre><code>    private function level1GameLoop():void
      {
          groundCollision();
          movementCode();
          scrollLevel();
      }
  </code></pre>
  
  <p>Ground collision takes care of making sure the player doesn't fall (ground is the level overall, apologies for the bad naming convention(s). </p>
  
  <pre><code>    private function groundCollision():void 
      {
          if (ground.bottom.hitTestPoint(character.x + 13, character.y, true || ground.bottom.hitTestPoint(character.x + 13, character.y, true)))
          {
              trace("h");
              while (ground.bottom.hitTestPoint(character.x + 13, character.y, true || ground.bottom.hitTestPoint(character.x + 13, character.y, true)))
              {
                  character.incrementUp();
                  if (ground.bottom.hitTestPoint(character.x + 13, character.y, true || ground.bottom.hitTestPoint(character.x + 13, character.y, true)))
                  {
                  }
                  else{
                      character.keepOnGround();
                  }
              }
          }
      }
  </code></pre>
  
  <p>and then you have your typical movement code </p>
  
  <pre><code>        else if (rightKey)
          {
              character.moveRight();
              lookingRight = true;
              lookingLeft = false;
          }
          else if (leftKey)
          {
              lookingLeft = true;
              lookingRight = false;
              character.moveLeft();
          }
  </code></pre>
  
  <p>Before scrolling the level, I tested to see does my character hit all of the platforms and yes he does.</p>
  
  <p>So now I want to implement scrolling.</p>
  
  <p>In the class definition I have set up a variable called container which is a sprite. </p>
  
  <pre><code>    private var container:Sprite = new Sprite();
  </code></pre>
  
  <p>I have then added my children on to the stage before starting the game loop </p>
  
  <pre><code>        addChild(container);
          container.addChild(ground);
          container.addChild(character);
          addChild(timerGIF);//this does not need to scroll 
  </code></pre>
  
  <p>I have then tested the game again, and the collision works fine.</p>
  
  <p>Now I have tried many attempts to scroll the player and keep him on center of the screen making sure that the collisions still function correctly.</p>
  
  <p>private function scrollLevel():void 
          {</p>
  
  <pre><code>        /*
          _camera.x = character.x - stage.stageWidth * 0.5;
          _camera.y = character.y - stage.stageHeight * 0.5;
          //"camera" must not show areas outside of the game world
          if (_camera.x &lt; 0) 
          {
              _camera.x = 0;
          }
          //Right
          if (_camera.x &gt; (container.width) - stage.stageWidth) 
          {
              _camera.x = (container.width) - stage.stageWidth;
          }
          //Bottom
          if (_camera.y &gt; (container.height) - stage.stageHeight) 
          {
              _camera.y = (container.height) - stage.stageHeight;
          }
          //Top
          if (_camera.y &lt; 0) 
          {
              _camera.y = 0;
          }
  
          container.scrollRect = _camera;
          */
  
          //ground.x = -character.x + stage.stageWidth / 2;
      //  ground.y = -character.y + stage.stageHeight / 2;
  
  
              /*var offset:int = 10;
              var distance:Number = character.x - ((stage.stageWidth / 2) + offset);
              var distance2:Number = character.y - ((stage.stageHeight / 2));
              var ease:int = 5;
              if (distance &lt; 0)
              {
                  distance *= -1;
              }
              if (distance2 &lt; 0)
              {
                  distance2 *= -1;
              }
              if (character.x &lt; (stage.stageWidth / 2))
              {
                  var variable:int = distance / ease;
                  //character.x += variable;
                  container.x += variable;
  
  
  
              }
              if (character.x &gt; (stage.stageWidth / 2))
              {
                  var variable2:int = distance / ease;
                  //character.x -= variable2;
                  container.x -= variable2;
  
  
              }
  
              /*if (character.y &lt; (stage.stageHeight / 2))
              {
                  var variable3:int = distance2 / ease;
                  character.y += variable3;
                  //container.y += variable3;
  
  
  
              }
  
              if (character.y &gt; (stage.stageHeight / 2))
              {
                  var variable4:int = distance2 / ease;
                  character.y -= variable4;
                  //container.y -= variable4;
  
              }*/
  
              /*var camera:Point = new Point();
  
              // Set the camera coordinates to the char coordinates.
              camera.x = character.x;
              camera.y = character.y;
  
              // Adjust the world position on the screen based on the camera position.
              ground.x = -camera.x + (stage.stageWidth / 2);
              ground.y = -camera.y + (stage.stageHeight / 2);*/
  
      }
  </code></pre>
  
  <p>None of these seem to work, since the collision then gets all muddled up.</p>
  
  <p>By this I mean, my character ends up floating, or falling through </p>
  
  <p>Other things to mention, ground is a movie clip and is basically my level(once again, poor naming conventions, apoligiez).</p>
  
  <p>Inside ground there are hitTest box's and objects that the character will get. </p>
  
  <p><img src="https://i.stack.imgur.com/uGwt7.png" alt="Please Check"></p>