Copy link to clipboard
Copied
I encountered a little difficulty, as follows, when I used the camera, the elements that were originally centered on the stage were moved to the outside of the stage.
I hope that after using the command to select the element, it can be automatically centered without being affected by the camera.
I checked the relevant API. When the camera is not turned on, the command works fine. However, after it is turned on, it cannot be centered. The xy position information of the element is different when the camera is turned on and off.
Can you provide some implementation ideas? Or give the relevant code directly, thank you very much!
1 Correct answer
Hi.
The camera will offset and scale everything on stage according to its settings. Centering won't happen on selection.
You need to adjust camera's x, y, and zoom properties accordingly to get the results that you want.
Regards,
JC
Copy link to clipboard
Copied
Hi.
The camera will offset and scale everything on stage according to its settings. Centering won't happen on selection.
You need to adjust camera's x, y, and zoom properties accordingly to get the results that you want.
Regards,
JC
Copy link to clipboard
Copied
When I paste elements copied from other documents into the current document, because the camera is offset, the elements will be very far away and very difficult to find.
The following is one of my ideas. First get the xy coordinates of the camera and apply them to the selected element (while exchanging the xy position), but you can only move the element near the stage.
//Get the current camera coordinates
var tl = an.getDocumentDOM().getTimeline();
var currentFrame = tl.currentFrame;
var cameraPos = tl.camera.getPosition(currentFrame);
an.trace("Camera position: x = " + cameraPos.x + ", y = " + cameraPos.y);
var selection = an.getDocumentDOM().selection[0];
// Set the position of the selected element to the position of the camera
selection.x = cameraPos.y;
selection.y = cameraPos.x;
an.getDocumentDOM().selectNone();
I may have missed something, but there is no reason why it can't be implemented. This camera should also have its own range box. The manual contains too little content. I can't figure out what other feasible methods are available.

