Skip to main content
Multoman
Inspiring
March 5, 2023
Answered

how do I find the coordinates of a figure relative to the scene ?

  • March 5, 2023
  • 1 reply
  • 549 views

How to use JSFL to calculate the coordinates of the figure relative to the center of the scene, given that the figure is in the symbol and the symbol has its own center?

 

This topic has been closed for replies.
Correct answer Vladin M. Mitov

Hi,
To obtain the "screen" coordinates of a given element, you can multiply its matrix with the document.viewMatrix and then take the tx and ty of the resulting product. Alternatively, you can use the fl.Math.transformPoint() method.

 

 

// Method 1:
var doc = fl.getDocumentDOM();
var el = doc.selection[0];
var m = fl.Math.concatMatrix( el.matrix, doc.viewMatrix );
fl.trace( "x: " + m.tx + ", y: " + m.ty );


// Method 2:
var doc = fl.getDocumentDOM();
var el = doc.selection[0];
var pos = fl.Math.transformPoint( doc.viewMatrix, {x:el.matrix.tx, y:el.matrix.ty} );
fl.trace( "x: " + pos.x + ", y: " + pos.y );

 

 



1 reply

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
March 6, 2023

Hi,
To obtain the "screen" coordinates of a given element, you can multiply its matrix with the document.viewMatrix and then take the tx and ty of the resulting product. Alternatively, you can use the fl.Math.transformPoint() method.

 

 

// Method 1:
var doc = fl.getDocumentDOM();
var el = doc.selection[0];
var m = fl.Math.concatMatrix( el.matrix, doc.viewMatrix );
fl.trace( "x: " + m.tx + ", y: " + m.ty );


// Method 2:
var doc = fl.getDocumentDOM();
var el = doc.selection[0];
var pos = fl.Math.transformPoint( doc.viewMatrix, {x:el.matrix.tx, y:el.matrix.ty} );
fl.trace( "x: " + pos.x + ", y: " + pos.y );

 

 



- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Multoman
MultomanAuthor
Inspiring
March 6, 2023

Thank you Vladin. As always you are the best!