A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: x and y coordinates and angle

Hybrid View

  1. #1
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i answered your question in the first part of my reply.

    for AS2, properties have an underscore before the name. your code says "rock.x" - it should be "rock._x" - notice the underscore. i'll repaste the corrected code:

    PHP Code:
    onClipEvent(enterFrame){ 
        
    trace(rock._x); 
        
    trace(rock._y); 
        } 
    for angles, the most simple formula is this:

    PHP Code:
    var TO_RAD Math.PI/180;
    object._x Math.sin(angle TO_RAD) * distance;
    object._y Math.cos(angle TO_RAD) * distance
    so if you wanted rock to be positioned at 100 pixels 45 degrees from 0, 0, you'd use:

    PHP Code:
    var TO_RAD Math.PI/180;
    rock._x Math.sin(45 TO_RAD) * 100;
    rock._y Math.cos(45 TO_RAD) * 100
    note that this very simple method will start at the 6 o'clock position and go CCW.

    neznein from this board has a nice (and much more informative) post about it here: http://www.calypso88.com/?p=512
    Last edited by moagrius; 12-08-2010 at 10:53 PM. Reason: clarification

Tags for this Thread

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