public void CopyValuesTo(CompositeAnimation target, CompositeEntity newParent)
 {
     target.Parent = newParent;
     target.Name   = this.Name;
     target.LerpLastFrameWithFirst = this.LerpLastFrameWithFirst;
     target.IsPaused        = this.IsPaused;
     target.IsStopped       = this.IsStopped;
     target.LoopMax         = this.LoopMax;
     target.Speed           = this.Speed;
     target.AutoPlay        = this.AutoPlay;
     target.HideWhenStopped = this.HideWhenStopped;
     // copy keyframes
     for (int i = 0; i < this._keyFrames.Count; i++)
     {
         // if no particle type is available
         if (target.KeyFrames.Count <= i)
         {
             target.KeyFrames.Add(new CompositeKeyFrame(target));
         }
         this.KeyFrames[i].CopyValuesTo(target.KeyFrames[i], target);
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.KeyFrames.Count; i > this.KeyFrames.Count; i--)
     {
         target.KeyFrames.RemoveAt(i - 1);
     }
     target.Reset();
 }
        public override void CopyValuesTo(SceneItem target)
        {
            base.CopyValuesTo(target);
            CompositeEntity compositeEntity = target as CompositeEntity;

            if (this.RootBone == null)
            {
                compositeEntity.RootBone = null;
            }
            else
            {
                this.RootBone.CopyValuesTo(compositeEntity.RootBone, null, compositeEntity);
            }

            // copy animations
            for (int i = 0; i < this._animations.Count; i++)
            {
                // if no animation is available
                if (compositeEntity.Animations.Count <= i)
                {
                    compositeEntity.Animations.Add(new CompositeAnimation(compositeEntity));
                }
                this.Animations[i].CopyValuesTo(compositeEntity.Animations[i], compositeEntity);
                compositeEntity.Animations[i].Parent = compositeEntity;
            }
            // Remove remaining animations (can cause garbage!)
            for (int i = compositeEntity.Animations.Count; i > this.Animations.Count; i--)
            {
                compositeEntity.Animations.RemoveAt(i - 1);
            }
            // copy bank
            foreach (String key in this.SceneItemBank.Keys)
            {
                // if the entry is not available, create it
                if (compositeEntity.SceneItemBank.ContainsKey(key) == false ||
                    this.SceneItemBank[key].GetType() != compositeEntity.SceneItemBank[key].GetType())
                {
                    //Can't just create a blank sceneitem. it won't create a new instance of AnimatedSprite for instance
                    SceneItem newItem = CreateNewInstaceCopyOf(this.SceneItemBank[key]);
                    compositeEntity.SceneItemBank[key] = newItem;
                }
                this.SceneItemBank[key].CopyValuesTo(compositeEntity.SceneItemBank[key]);
            }
            // Remove remaining unused key (can cause garbage!)
            List <String> keysToRemove = new List <string>();

            foreach (String key in compositeEntity.SceneItemBank.Keys)
            {
                if (this.SceneItemBank.ContainsKey(key) == false)
                {
                    keysToRemove.Add(key);
                }
            }
            foreach (String key in keysToRemove)
            {
                compositeEntity.SceneItemBank.Remove(key);
            }
        }
 public CompositeAnimation(CompositeEntity parent)
 {
     _keyFrames                  = new List <CompositeKeyFrame>();
     _name                       = "New Animation";
     _currentLife                = 0;
     _currentKeyFrameIndex       = 0;
     _loopMax                    = 0;
     _loopCounter                = 0;
     _speed                      = 1;
     this.Parent                 = parent;
     this.AutoPlay               = true;
     this.LerpLastFrameWithFirst = true;
 }
 public void CopyValuesTo(CompositeBone target, CompositeBone parentBone,
                          CompositeEntity newParentEntity)
 {
     target.Parent            = newParentEntity;
     target.ParentBone        = parentBone;
     target.Name              = this.Name;
     target.SceneItem         = this.SceneItem;
     target.SubItem           = this.SubItem;
     target.InheritPosition   = this.InheritPosition;
     target.InheritRotation   = this.InheritRotation;
     target.InheritScale      = this.InheritScale;
     target.InheritVisibility = this.InheritVisibility;
     target.MasterVisibility  = this.MasterVisibility;
     target.Interpolate       = this.Interpolate;
     // copy bones
     for (int i = 0; i < this.ChildBones.Count; i++)
     {
         CompositeBone targetCBone;
         bool          addToList = false;
         // if no child bone is available, create a new one
         if (target.ChildBones.Count <= i)
         {
             targetCBone = new CompositeBone();
             addToList   = true;
         }
         else
         {
             targetCBone = target.ChildBones[i];
         }
         this.ChildBones[i].CopyValuesTo(targetCBone, target, newParentEntity);
         if (addToList == true)
         {
             target.AddChildBone(targetCBone);
         }
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.ChildBones.Count; i > this.ChildBones.Count; i--)
     {
         target.ChildBones.RemoveAt(i - 1);
     }
 }
Beispiel #5
0
        public void Draw(float elapsed)
        {
            if (Parent == null)
            {
                throw new Exception("The Parent of this boneTransform isn't set");
            }
            SceneItem item = GetSceneItem();

            if (item != null)
            {
                if (_currentVisibleState == true)
                {
                    CompositeEntity parentEntity     = Parent.Parent.Parent;
                    Vector2         tmpPivot         = item.Pivot;
                    bool            tmpPivotRelative = item.IsPivotRelative;
                    item.Rotation = parentEntity.Rotation + _rotation;
                    item.Scale    = parentEntity.Scale * _scale;
                    item.Visible  = true;
                    item.Position = parentEntity.Position + _position;
                    float parentOpacityFactor = parentEntity.Opacity / 255.0f;
                    if (_opacity.HasValue)
                    {
                        item.Opacity = (byte)(_opacity.Value * parentOpacityFactor);
                    }
                    else
                    {
                        item.Opacity = parentEntity.Opacity;
                    }
                    item.Layer           = parentEntity.Layer;
                    item.Pivot           = _transformPivot;
                    item.IsPivotRelative = false;
                    item.Draw(elapsed);
                    item.Pivot           = tmpPivot;
                    item.IsPivotRelative = tmpPivotRelative;
                }
                else
                {
                    item.Visible = false;
                }
            }
        }
Beispiel #6
0
        public SceneItem GetSceneItem()
        {
            String targetItem = null;

            // use the default if no local override
            if (String.IsNullOrEmpty(_sceneItem) == true)
            {
                targetItem = this.Bone.SceneItem;
            }
            else
            {
                targetItem = _sceneItem;
            }
            CompositeEntity parentEntity = Parent.Parent.Parent;

            if (String.IsNullOrEmpty(targetItem) == false &&
                parentEntity.SceneItemBank.ContainsKey(targetItem))
            {
                return(parentEntity.SceneItemBank[targetItem]);
            }
            return(null);
        }
Beispiel #7
0
        public void LerpSceneItemWith(CompositeBoneTransform nextState, float amount, bool nextStateOverride)
        {
            // original is only used when bone.Interpolate is set to false, and refer to the 1st KF of the 1st anim
            SceneItem item    = GetSceneItem();
            String    subItem = GetSubItem();

            if (String.IsNullOrEmpty(subItem) == false && item is ISubItemCollection)
            {
                ((ISubItemCollection)item).SetCurrentSubItem(subItem);
            }
            if (item != null)
            {
                item.Update(1 / 60f);
                amount = MathHelper.Clamp(amount, 0, 1);
                CompositeEntity        parentEntity    = Parent.Parent.Parent;
                CompositeBoneTransform parentTransform = this.ParentBoneTransform;
                _currentVisibleState = GetVisibilityState(parentTransform);
                if (_currentVisibleState == false)
                {
                    return;
                }
                bool nextStateVisibility = nextState.GetVisibilityState(nextState.ParentBoneTransform);
                // no lerping if the next state isnt visible
                if (nextStateVisibility == false)
                {
                    nextState = this;
                }
                if (nextStateOverride == true)
                {
                    _position = nextState.Position;
                    _scale    = nextState.Scale;
                    _rotation = nextState.Rotation;
                }
                else
                {
                    _position = Vector2.Lerp(this.Position, nextState.Position, amount);
                    _scale    = Vector2.Lerp(this.Scale, nextState.Scale, amount);
                    _rotation = MathHelper.Lerp(this.Rotation, nextState.Rotation, amount);
                }
                if (this.Opacity.HasValue == true || nextState.Opacity.HasValue == true)
                {
                    if (this.Opacity.HasValue == true && nextState.Opacity.HasValue == false)
                    {
                        _opacity = this.Opacity.Value;
                    }
                    else if (this.Opacity.HasValue == false && nextState.Opacity.HasValue == true)
                    {
                        _opacity = nextState.Opacity.Value;
                    }
                    else
                    {
                        _opacity = SquidMath.Lerp(this.Opacity.Value, nextState.Opacity.Value, amount);
                    }
                }
                else
                {
                    _opacity = null;
                }
                _transformPivot     = item.GetAbsolutePivot(false);
                item.FlipHorizontal = parentEntity.FlipHorizontal ^ this.FlipHorizontal;
                item.FlipVertical   = parentEntity.FlipVertical ^ this.FlipVertical;
                if (parentEntity.FlipHorizontal == true)
                {
                    _position.X       = -_position.X;
                    _transformPivot.X = item.BoundingRectSize.X - _transformPivot.X;
                    _rotation         = -_rotation;
                }
                if (parentEntity.FlipVertical == true)
                {
                    _position.Y       = -_position.Y;
                    _transformPivot.Y = item.BoundingRectSize.Y - _transformPivot.Y;
                    _rotation         = -_rotation;
                }
                if (parentEntity.Scale != Vector2.One)
                {
                    _position *= parentEntity.Scale;
                }
                if (parentEntity.Rotation != 0)
                {
                    Vector2 offset = _position;
                    float   length = offset.Length();
                    double  angle  = Math.Atan2((float)offset.Y, (float)offset.X) + parentEntity.Rotation;
                    offset.X  = (float)(length * Math.Cos(angle));
                    offset.Y  = (float)(length * Math.Sin(angle));
                    _position = offset;
                }
                if (parentTransform != null)
                {
                    if (this.InheritRotation.HasValue == false && this.Bone.InheritRotation == true ||
                        this.InheritRotation.HasValue == true && this.InheritRotation == true)
                    {
                        _rotation += parentTransform.CurrentRotation;
                    }
                    if (this.InheritScale.HasValue == false && this.Bone.InheritScale == true ||
                        this.InheritScale.HasValue == true && this.InheritScale == true)
                    {
                        _scale *= parentTransform.CurrentScale;
                    }
                    if (this.InheritPosition.HasValue == false && this.Bone.InheritPosition == true ||
                        this.InheritPosition.HasValue == true && this.InheritPosition == true)
                    {
                        Vector2 offset = _position;
                        float   length = offset.Length();
                        double  angle  = Math.Atan2((float)offset.Y, (float)offset.X) + parentTransform._rotation;
                        offset.X  = (float)(length * Math.Cos(angle));
                        offset.Y  = (float)(length * Math.Sin(angle));
                        _position = parentTransform.CurrentPosition + offset;
                    }
                }
            }
        }