Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

package com.gebauz.Bauzoid.graphics.sprite;

/** Define a single frame within the animation.
 * Acts similar to an AtlasSpriteInstance in that it
 * has it's own coordinate, size, rotation and pivot parameters.
 *
 * The coordinate parameter is relative to the owning AnimatedSprite's pivot.
 * The size parameter allows single frames to have scaling.
 * The pivot parameter defines the moving, scaling and rotation point for this
 * single frame.
 * The rotation parameter defines the rotation of this single frame.
 */

public class AnimationFrame
{
        // Position of frame relative to parent AnimatedSprite's pivot
        public float x = 0.0f;
        public float y = 0.0f;
       
        // Size of frame
        public float w = 0.0f;
        public float h = 0.0f;
       
        // Rotation of frame
        public float angle = 0.0f;
       
        // Mirroring parameters of frame
        public boolean mirrorX = false;
        public boolean mirrorY = false;
       
        // Internal pivot
        public float pivotX = 0.0f;
        public float pivotY = 0.0f;
       
        private int mRegionIndex = -1;
        private float mDuration = 0.0f;
        private float mBeginTime = 0.0f;
        private float mEndTime = 0.0f;
       
        public AnimationFrame(AnimatedSprite sprite, int regionIndex, float duration)
        {
                mRegionIndex = regionIndex;
                mDuration = duration;
               
                // default values
                w = sprite.getRegionWidth(mRegionIndex);
                h = sprite.getRegionHeight(mRegionIndex);
                pivotX = w/2;
                pivotY = h/2;
        }
       
        /** Set absolute begin and end times within the full animation. */
        public void setBeginEnd(float begin, float end)
        {
                mBeginTime = begin;
                mEndTime = end;
        }
       
        /** Get region index into AtlasSprite of the frame. */
        public final int getRegionIndex()
        {
                return mRegionIndex;
        }
       
        /** Get duration of the frame. */
        public final float getDuration()
        {
                return mDuration;
        }
       
        /** Get the absolute begin time. */
        public final float getBeginTime()
        {
                return mBeginTime;
        }
       
        /** Get the absolute end time. */
        public final float getEndTime()
        {
                return mEndTime;
        }
       
        /** Check if the position is within this frame's begin and end. */
        public final boolean isInFrame(float pos)
        {
                return ((pos >= mBeginTime) && (pos <= mEndTime));
        }
}