Ejemplo n.º 1
0
        // Internal set clip, reset all
        void SetClip(tk2dSpriteAnimationClip clip)
        {
            if (this.clip != clip)
            {
                // reset stuff
                this.clip = clip;

                timelineEditor.Reset();

                if (!repeatPlayAnimation)
                {
                    playAnimation = false;
                }
                this.Animator.Stop();

                // build frame groups
                if (clip != null)
                {
                    if (CheckValidClip(clip))
                    {
                        // check if clip is valid?
                        frameGroups.Clear();
                        tk2dSpriteCollectionData lastSc = null;
                        int        lastSpriteId         = -1;
                        FrameGroup frameGroup           = null;
                        for (int i = 0; i < clip.frames.Length; ++i)
                        {
                            tk2dSpriteAnimationFrame f = clip.frames[i];
                            if (f.spriteCollection != lastSc || f.spriteId != lastSpriteId)
                            {
                                if (frameGroup != null)
                                {
                                    frameGroups.Add(frameGroup);
                                }
                                frameGroup = new FrameGroup();
                                frameGroup.spriteCollection = f.spriteCollection;
                                frameGroup.spriteId         = f.spriteId;
                            }
                            lastSc       = f.spriteCollection;
                            lastSpriteId = f.spriteId;
                            frameGroup.frames.Add(f);
                        }
                        if (frameGroup != null)
                        {
                            frameGroups.Add(frameGroup);
                        }

                        // Select first frame group
                        if (frameGroups.Count > 0)
                        {
                            timelineEditor.CurrentState.selectedFrame = 0;
                        }
                    }
                }
            }
        }
        // Internal set clip, reset all
        void SetClip(tk2dSpriteAnimationClip clip)
        {
            if (this.clip != clip)
            {
                // reset stuff
                this.clip = clip;

                timelineEditor.Reset();

                if (!repeatPlayAnimation)
                {
                    playAnimation = false;
                }
                this.Sprite.Stop();

                // build frame groups
                if (clip != null)
                {
                    frameGroups.Clear();
                    tk2dSpriteCollectionData lastSc = null;
                    int        lastSpriteId         = -1;
                    FrameGroup frameGroup           = null;
                    for (int i = 0; i < clip.frames.Length; ++i)
                    {
                        tk2dSpriteAnimationFrame f = clip.frames[i];
                        if (f.spriteCollection != lastSc || f.spriteId != lastSpriteId)
                        {
                            if (frameGroup != null)
                            {
                                frameGroups.Add(frameGroup);
                            }
                            frameGroup = new FrameGroup();
                            frameGroup.spriteCollection = f.spriteCollection;
                            frameGroup.spriteId         = f.spriteId;
                        }
                        lastSc       = f.spriteCollection;
                        lastSpriteId = f.spriteId;
                        frameGroup.frames.Add(f);
                    }
                    if (frameGroup != null)
                    {
                        frameGroups.Add(frameGroup);
                    }
                }
            }
        }