I am adding "layer" objects to the stage with a depth value.
I have then created my own camera class. When I tell the camera to move to the right what Im actually doing is telling each layer object to move to the left.
The distance that the layer moved to the left is based on the value of its depth variable...
var fCameraDepth = 1;
var fTan:Number = Math.tan( fCameraMovement / fCameraDepth );
oLayer.x += fTan * fLayerDepth
This works well and gives me a really nice parallax effect. The problem I'm having is that I want to be able to tell the camera to look at a movie clip on any layer but I'm having trouble figuring out how to convert the movie clips coordinates to the cameras depth.
Im trying something like this...
var fCameraDepth = 1;
var fCameraPosition:Number = oCamera.x;
// the layer will have a + or - x val compared to the camera so we
// need to take that into account when getting the targets position
var fTargetPosition:Number = oActor.x + oActor.getLayer().x;
var fTargetDepth:Number = oActor.getLayer().getDepth();
var fTan:Number = Math.tan( fTargetPosition / fTargetDepth );
var fTargetPositionAdjusted:Number = fTan * fCameraDepth;
oCamera.x = fTargetPositionAdjusted;
But the camera just wanders off somewhere (no where near the movie clip)
Can anyone get their head around this?