aduros / flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
https://github.com/aduros/flambe/wiki
MIT License
745 stars 118 forks source link

Is there a way to get the sprite value as it is from a particular frame of Movie #333

Open ramachandran-prazas opened 9 years ago

ramachandran-prazas commented 9 years ago

Is there a way to get the sprite value as it is from a particular frame of Movie (flump exported).

For example if i have a animation where rotation of a balloon is changing, and I want the contents of a particular frame along with its rotation applied instead of the original symbol image.

Thanks.

markknol commented 9 years ago

You can get this from the Sprite local matrix using mySprite.getLocalMatrix(). I wrote a utilty class to grab the rotation out of it.

import flambe.math.Matrix;

/**
 * Utility mixins for Matrix. Designed to be imported with 'using'.
 * @author Mark Knol
 */
class MatrixUtils
{
    inline public static function getX(matrix:Matrix):Float
    {
        return matrix.m02;
    }   

    inline public static function getY(matrix:Matrix):Float
    {
        return matrix.m12;
    }   

    inline public static function getScaleX(matrix:Matrix):Float
    {
        return Math.sqrt(matrix.m00 * matrix.m00 + matrix.m01 * matrix.m01);
    }   

    inline public static function getScaleY(matrix:Matrix):Float
    {
        return Math.sqrt(matrix.m10 * matrix.m10 + matrix.m11 * matrix.m11);
    }   

    inline public static function getRotation(matrix:Matrix):Float
    {
        return Math.atan(-matrix.m01  / matrix.m00);
    }   
}