Scrolling

Hello. Well basically my camera should follow the main character ( platform game). But there is one problem .. The character is not in the frame .. He is created in the frame with a function so i cant give him an instance name . The best thing i managed to do so far is to use the mouse to grab,ungrab the camera and move it .. but that is not so useful since i am going to use the mouse click to drop some stuff..So if anyone got any suggestion tell me ... btw here`s how the char is created in the frame

Code:
public function Create(x:Number, y:Number, width:Number = 50, height:Number = 80){
               bodyDef = new b2BodyDef();
               bodyDef.position.x = (x)/physScale;
               bodyDef.position.y = (y)/physScale;
               boxDef = new b2PolygonDef();
               boxDef.SetAsBox(GetRealWH(20), GetRealWH(20));
               boxDef.density = 1.0;
               boxDef.friction = 0.3;
               boxDef.restitution = 0.2;
               bodyDef.userData = new PlayerBox();
               bodyDef.userData.name = "jumper";
               bodyDef.userData.width = physScale * 2 * GetRealWH(width);
               bodyDef.userData.height = physScale * 2 * GetRealWH(height);
               body = m_world.CreateBody(bodyDef);
               body.SetBullet(true);
               body.CreateShape(boxDef);
               body.SetMassFromShapes();
               bodyDef.userData.body = body;
               addChild(bodyDef.userData);

metodski wrote:
Hello. Well basically my camera should follow the main character ( platform game). But there is one problem .. The character is not in the frame .. He is created in the frame with a function so i cant give him an instance name . The best thing i managed to do so far is to use the mouse to grab,ungrab the camera and move it .. but that is not so useful since i am going to use the mouse click to drop some stuff..So if anyone got any suggestion tell me ... btw here`s how the char is created in the frame


Why on earth does giving your player an instance name make a difference? Anyway, just take your world display object and subtract the player's position every frame, something like so:

Code:
function myStepFunction() {
    world.x = 0 - player.x;
    world.y = 0 - player.y;
}


Of course, depending on how your code is structured you'll have to tweak. That's the basic idea though.
Sorry im not .. umm uhh .. im not following you .. world object... my frame does not have anything ... just a blank frame .. everything is created from .as file
So what?
Ok i got it thx for the help 🙂

Code:
var TheChild = getChildByName("Player");
         y = -TheChild.y + 300;

Original thread: https://box2d.org/forum/viewtopic.php?t=2586