Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Automated position shift based on composition size

  • Automated position shift based on composition size

    Posted by Kristel Ottis on September 12, 2011 at 1:52 am

    This one’s an easy one for any AExperts who know anything about expressions. Thanks in advance for your help!

    I’m working with sprite sheets of varying widths based on how many characters they contain (comps at 30fps). I started out thinking the relative position between the frames in the sprite sheet would be the same (in this particular instance, 242px), so I used this:

    posterizeTime(30);
    x = (time / thisComp.frameDuration) * -242;
    value + [x, 0]

    This worked great until I realized that the other sprite sheets that I would be getting would all be different in width, so I need a script to do the math based on the comp width in pixels and the total number of frames.

    I used different variations of thisComp.Width and thisComp.duration, but seem to be missing something to complete the calculation – any suggestions?

    Extra super thanks if you can tell me how to automate moving to the next row on the sprite sheet once I come to the rightmost frame!

    posterizeTime(30);
    x = (time / thisComp.frameDuration) * -242;
    value + [x, 0]

    Kristel Ottis replied 14 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    September 12, 2011 at 2:31 am

    Assuming that your comp is the width and height of one sprite and the layer is positioned so that the sprite in the upper left corner is visible, it’s probably going to look something like this:

    nCol = Math.round(width/thisComp.width);
    f = timeToFrames();
    c = f%nCol;
    r = Math.floor(f/nCol);
    value – [thisComp.width*c, thisComp.height*r]

    Dan

  • Kristel Ottis

    September 12, 2011 at 4:02 am

    Thanks for the quick reply – that is massively helpful!

    Now if only I could teach AE to update the comp size based on scanning the sheet to figure out how many frames are in a row… (will always vary, depending on the size of the content in an individual frame)

    That, and finalize the viz and export for the client and set a timer for my coffee machine in the morning so I can just go to bed:D

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy