Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 516329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:43:12+00:00 2026-05-13T07:43:12+00:00

I am adding layer objects to the stage with a depth value. I have

  • 0

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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:43:12+00:00Added an answer on May 13, 2026 at 7:43 am

    Camera depth should be relative to the layer — I.E., fCameraDepth – fTargetDepth.

    Make the equation that links camera position to object position. Then reverse the equation algebraically. My guess is that it will involve atan.

    For a simpler implementation, I might recommend that depth be simply a variable between 0 and 1. Objects at 0 are infinitely far in the distance, and objects at 1 are at the camera’s depth. Doing this will result in far easier math, that doesn’t involve tangent or arc tangent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an empty movie clip(say A) on a layer and then I have
i have a CCLayer class on top of which i am adding another CClayer
I'm tinkering with adding a model layer to an iPhone application so that I
Normally when adding sprites to a layer in cocos2d I'd just add a pointer
I'm in the process of adding a Data Access Layer for our ASP.Net 2.0
What is the equivalent of UIViewAnimationOptionBeginFromCurrentState flag when adding CABasicAnimation directly to the layer?
Adding Exceptional Handling is a good practise, but I have a doubt, In our
Adding functionality to a class can be done by adding a method or by
How do I go about creating a list of objects (class instances) in Python?
Here's the architecture of my app: I have a data access layer in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.