A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [help] Camera control

  1. #1
    Member
    Join Date
    Mar 2000
    Location
    Atlanta
    Posts
    83

    [help] Camera control

    All,
    I am making a Camera class for my games and I am having an issue with one of my pan modes.

    I have a QuickPan which uses the 'divide the distance' method an works fine.

    Code:
    //the deltas
    var camDX = camx-x;
    var camDY = camy-y;
    //delta divided by QuickPan speed
    cameraTargetX -= camDX/qpan_time;
    cameraTargetY -= camDY/qpan_time;
    //set the position
    clip._x = -cameraTargetX;
    clip._y = -cameraTargetY;
    I am trying to create a mode that is panning by a specified speed (i.e. always move 5 pixels per tick to the target) I cannot figure out the math. I can get it going forward fine, but I cannot get it going backwards.

    For example.
    cam.panTo(150,100); // this works fine
    now do:
    cam.panTo(225,100); // this also works fine
    now do:
    cam.panTo(150,100); // now it pans forward, when it should pan BACK to 150

    My speed is always a positive integer (cam.setPanSpeed(5)) and my xVel and yVel always resolve to positive integers as a result.

    Maybe I am just going about this the totally wrong way. Can anyone offer any ideas?

    thanks,
    brad

  2. #2
    Member
    Join Date
    Mar 2000
    Location
    Atlanta
    Posts
    83
    bump

  3. #3
    Senior Member sand858's Avatar
    Join Date
    Aug 2001
    Posts
    327
    Post your panTo function and I'll see what I can do.

    Logically it sounds like you are not taking into account the direction of the speed.

    cam.panTo(150,100); // no speed
    cam.panTo(225,100); // x has positive speed
    cam.panTo(150,100); // x has negative speed

    That's the only way I can explain that it continues to increase.

    Try tracing the camera's actual x values to see what's happening.

    What you need is something like this:

    if( newPosition < currentPosition )
    currentPosition -= speed;
    else
    currentPosition += speed;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center