コード例 #1
0
        protected void _InterpretAnimationData()
        {
            // make sure the animated sprite has been registered
            // (this is done to prevent errors that occur when trying to assign these values
            // during desrerialization.
            if (!IsRegistered)
                return;

            // make sure we have an animation data assigned
            if (_animationData == null)
                return;

            // make sure the animation data has been initialized
            if (!_animationData.IsInitialized)
            {
                // try to init
                _animationData.Init();

                // if still not initialized animation data must be borked...
                // quit now and drop the animation data to skip further initialization
                if (!_animationData.IsInitialized)
                {
                    Assert.Fatal(false, "T2DAnimatedSprite._InterpretAnimationData() - Initialization of animation data failed. Animation will not play.");
                    _animationData = null;
                    return;
                }
            }

            // pass the data on to the animation controller
            _ac.AnimationFrameCount = _animationData.AnimationFramesList.Count;
            _ac.AnimationDuration = _animationData.AnimationDuration;
            _ac.AnimationCycle = _animationData.AnimationCycle;

            // pass the material from the animation data to the quad
            _quad.Material = _animationData.Material;

            // set the texture coordinates dirty
            _currentFrameAreaDirty = true;

            // reset the animation data dirty flag
            _animationDataDirty = false;
        }
コード例 #2
0
        /// <summary>
        /// Plays the specified animation data. When that animation is completed, the animation currently playing (at the time you call this method)
        /// will be loaded and resume from the time specified.
        /// </summary>
        /// <param name="data">The animation to play</param>
        /// <param name="autoRestoreTime">The time in seconds from which to continue playing the current animation.</param>
        public void PlayAnimation(T2DAnimationData data, float autoRestoreTime)
        {
            // create and push a new animation cue to the front of the queue
            _animationQueue.Insert(0, new T2DAnimationCue(_animationData, autoRestoreTime));

            // play the specified animation
            PlayAnimation(data);
        }
コード例 #3
0
        /// <summary>
        /// Plays an animation with specified animation data and either queue up the currently playing animation to continue after 
        /// the specified animation is finished -or- clears all queued animations and does not auto-restore. If you do not wish to auto 
        /// restore the currently playing animation, but want to keep the animation queue intact, use the PlayAnimation(T2DAnimationData data) 
        /// version of this method.
        /// </summary>
        /// <param name="data">The animation data to use.</param>
        /// <param name="autoRestoreAnimation">True if the animated sprite should return to it's current animation once the specified animation 
        /// is finished. False if the animation should not auto restore and the entire animation queue should be cleared.</param>
        public void PlayAnimation(T2DAnimationData data, bool autoRestoreAnimation)
        {
            // either insert the current animation at the beginning of the the animation queue
            // or clear the animation queue entirely
            if (autoRestoreAnimation)
                _animationQueue.Insert(0, GenerateAnimationCue());
            else
                _animationQueue.Clear();

            // replace the current animation data with the one specified
            PlayAnimation(data);
        }
コード例 #4
0
 /// <summary>
 /// Generates and adds an animation cue to the animation queue to be played after all animations are finished.
 /// </summary>
 /// <param name="animData">The animation data to add to the animation queue.</param>
 public void EnqueueAnimation(T2DAnimationData animData)
 {
     // creates an animation cue for the specified animation data
     // at time 0 and adds it to the queue
     _animationQueue.Add(new T2DAnimationCue(animData, 0.0f));
 }
コード例 #5
0
        /// <summary>
        /// Plays an animation with specified animation data.
        /// </summary>
        /// <param name="data">animation data</param>
        public void PlayAnimation(T2DAnimationData data)
        {
            // replace the current animation data with the one specified
            AnimationData = data;

            // begin the new animation
            PlayAnimation();
        }
コード例 #6
0
            /// <summary>
            /// Adds a sound event to the specified frame of the specified animation.
            /// </summary>
            /// <param name="animation">The animation to add the step sound to.</param>
            /// <param name="frameIndex">The 0-based frame number of the specified animation on which to play the specified sound cue.</param>
            /// <param name="soundCueIndex">The sound cue to play on the specified frame of the specified animation.</param>
            public void AddStepSoundFrame(T2DAnimationData animation, int frameIndex, string soundCueIndex)
            {
                if (animation == null)
                    return;

                if (!_stepSoundAnimations.Contains(animation.Name))
                    _stepSoundAnimations.Add(animation.Name, new StepSoundTable(animation));

                StepSoundTable table = _stepSoundAnimations[animation.Name] as StepSoundTable;

                if (table != null)
                    table.AddStepFrame(frameIndex, soundCueIndex);
                else
                    ClearAnimationStepSounds(animation);
            }
コード例 #7
0
            /// <summary>
            /// Plays the specified animation on the Actor starting at the specified frame. Also responsible for playing sound events.
            /// </summary>
            /// <param name="animation">The animation to be played.</param>
            /// <param name="frameIndex">The frame at which to start the animation.</param>
            protected virtual void _playAnimation(T2DAnimationData animation, uint frameIndex)
            {
                // make sure the animation exists
                // (and that we actually have an actor component)
                if (_actorComponent != null && animation != null)
                {
                    uint targetFrame = frameIndex < animation.AnimationFramesList.Count ? frameIndex : 0;
                    _actorComponent._animatedSprite.PlayAnimation(animation);
                    _actorComponent._animatedSprite.SetAnimationFrame(targetFrame);

                    // if we're currently supposed to be managing sound events for this actor...
                    if (_actorComponent._useAnimationManagerSoundEvents)
                    {
                        // grab the sound event for this animation
                        string soundEvent = GetSoundEvent(animation);

                        // play the sound event if one exists
                        if (soundEvent != null)
                        {
                            float distance = Vector2.Distance((_actorComponent.SceneObject.SceneGraph.Camera as T2DSceneCamera).Position, _actorComponent._animatedSprite.Position);
                            _currentSoundCue = SoundManager.Instance.PlaySound(_actorComponent._soundBank, soundEvent, distance);
                        }
                    }

                    // if we're supposed to be doing step sounds...
                    if (_actorComponent._useAnimationStepSoundList)
                    {
                        // grab the sound table for this animation
                        StepSoundTable table = GetStepSoundTable(animation);

                        // table has frames, enable OnFrameChange callback
                        if (table != null && table.HasFrames)
                        {
                            _actorComponent._animatedSprite.OnFrameChange = OnFrameChange;

                            // special case: check for step sound on starting frame and play
                            if (table.StepSounds.Contains(frameIndex) && table.Enabled)
                            {
                                float distance = Vector2.Distance((_actorComponent.SceneObject.SceneGraph.Camera as T2DSceneCamera).Position, _actorComponent._animatedSprite.Position);
                                _currentSoundCue = SoundManager.Instance.PlaySound(_actorComponent._soundBank,
                                                                table.StepSounds[frameIndex] as string,
                                                                distance);
                            }
                        }
                    }
                }
            }
コード例 #8
0
            /// <summary>
            /// Set a sound cue to be played immediately when the specified animation is played.
            /// </summary>
            /// <param name="animation">The animation to attach the sound cue to.</param>
            /// <param name="soundCueIndex">The name of the sound cue.</param>
            public void SetSoundEvent(T2DAnimationData animation, string soundCueIndex)
            {
                if (animation == null)
                    return;

                ClearSoundEvent(animation);

                _soundEvents.Add(animation.Name, soundCueIndex);
            }
コード例 #9
0
            /// <summary>
            /// Add a transitional animation to be played between the two specified animation states.
            /// </summary>
            /// <param name="from">The name of the state to be transitioning from.</param>
            /// <param name="to">The name of the state to be transitioning to.</param>
            /// <param name="animationData">The animation to be played when transitioning from FromState to ToState.</param>
            public void SetTransition(string from, string to, T2DAnimationData animationData)
            {
                if (animationData == null)
                    return;

                Assert.Fatal(!animationData.AnimationCycle, "Transitional animations should not cycle! \n\nDo not add looping animations to an Actor's transition list.");

                ClearTransition(from, to);

                string hashKey = from + "_to_" + to;
                _transitions.Add(hashKey, animationData);
            }
コード例 #10
0
            /// <summary>
            /// Get the sound cue to be played when the specified animation is played.
            /// </summary>
            /// <param name="animation">The animation to check for.</param>
            /// <returns>The sound cue associated with the specified animation.</returns>
            public string GetSoundEvent(T2DAnimationData animation)
            {
                if (_soundEvents.Contains(animation.Name))
                    return _soundEvents[animation.Name] as string;

                return null;
            }
コード例 #11
0
            /// <summary>
            /// Get the step sound table associated with the specified animation.
            /// </summary>
            /// <param name="animation">The animation for which to retrieve the step sound table.</param>
            /// <returns>The step sound table associated with the specified animation.</returns>
            public StepSoundTable GetStepSoundTable(T2DAnimationData animation)
            {
                if (_stepSoundAnimations.Contains(animation.Name))
                    return _stepSoundAnimations[animation.Name] as StepSoundTable;

                return null;
            }
コード例 #12
0
            /// <summary>
            /// Remove any sound event from the specified frame of the specified animation.
            /// </summary>
            /// <param name="animation">The animation to remove the sound event from.</param>
            /// <param name="frame">The frame to remove the sound event from.</param>
            public void ClearStepSoundFrame(T2DAnimationData animation, int frame)
            {
                if (_stepSoundAnimations.Contains(animation.Name))
                {
                    StepSoundTable table = _stepSoundAnimations[animation.Name] as StepSoundTable;

                    if (table != null)
                        table.RemoveStepFrame(frame);
                    else
                        ClearAnimationStepSounds(animation);
                }
            }
コード例 #13
0
 /// <summary>
 /// Remove a sound event from the specified animation.
 /// </summary>
 /// <param name="animation">The animation to clear the sound event from.</param>
 public void ClearSoundEvent(T2DAnimationData animation)
 {
     if (_soundEvents.Contains(animation.Name))
         _soundEvents.Remove(animation.Name);
 }
コード例 #14
0
            /// <summary>
            /// Removes all step sounds from the specified animation.
            /// </summary>
            /// <param name="animation">The animation to clear step sounds from.</param>
            public void ClearAnimationStepSounds(T2DAnimationData animation)
            {
                if (_stepSoundAnimations.Contains(animation.Name))
                {
                    StepSoundTable table = _stepSoundAnimations[animation.Name] as StepSoundTable;

                    if (table != null)
                        table.ClearTable();

                    _stepSoundAnimations.Remove(animation.Name);
                }
            }
コード例 #15
0
 public T2DAnimatedSprite(T2DAnimationData _data)
     : this()
 {
     // record the specified animation data
     AnimationData = _data;
 }
コード例 #16
0
 /// <summary>
 /// Plays the specified animation on the Actor starting at frame 0. Also responsible for playing sound events.
 /// </summary>
 /// <param name="animation">The animation to be played.</param>
 protected virtual void _playAnimation(T2DAnimationData animation)
 {
     _playAnimation(animation, 0);
 }
コード例 #17
0
 public T2DAnimationCue(T2DAnimationData animationData, float cueTime)
 {
     _animationData = animationData;
     _restoreTime = cueTime;
 }
コード例 #18
0
 /// <summary>
 /// Constructor. Records the animation this tabls is associated with.
 /// </summary>
 /// <param name="animation"></param>
 public StepSoundTable(T2DAnimationData animation)
 {
     _animation = animation;
 }