コード例 #1
0
        /// <summary>
        /// Renders the provided <see cref="Entity"/> instance.
        /// </summary>
        /// <param name="entity"><see cref="Entity"/> instance to render.</param>
        public override void Process(Entity entity)
        {
            ImageComponent imageComponent = _imageMapper.Get(entity);

            if ((imageComponent == null) && !imageComponent.IsVisible)
            {
                return;
            }

            Vector2 position = imageComponent.Position;

            if (imageComponent.PositionMode == PositionMode.External)
            {
                PositionComponent positionComponent = _positionMapper.Get(entity);
                if (positionComponent != null)
                {
                    position += positionComponent.Position;
                }
            }

            float rotation = imageComponent.Rotation;

            if (imageComponent.RotationMode == RotationMode.External)
            {
                PositionComponent positionComponent = _positionMapper.Get(entity);
                if (positionComponent != null)
                {
                    rotation += positionComponent.Rotation;
                }
            }

            Director.SharedDirector.SpriteBatch.Draw(imageComponent.Texture,
                                                     position,
                                                     imageComponent.Source,
                                                     imageComponent.Tint,
                                                     rotation,
                                                     imageComponent.Origin,
                                                     imageComponent.Scale,
                                                     imageComponent.Effects,
                                                     imageComponent.Layer);
#if DEBUG
            ++ImagesRendered;
            ++ImagesProcessed;
#endif
        }
コード例 #2
0
        /// <summary>
        /// Updates the animation for the provided <see cref="Entity"/> instance.
        /// </summary>
        /// <param name="entity"><see cref="Entity"/> instance to render.</param>
        public override void Process(Entity entity)
        {
            if (!entity.IsActive)
            {
                return;
            }

            AnimationComponent animation = _animationMapper.Get(entity);

            if ((animation != null) && (animation.IsPlaying))
            {
                if (animation.ElapsedTimeSinceLastFrameChange >= animation.Frames[animation.FrameIndex].FrameLength)
                {
                    animation.ElapsedTimeSinceLastFrameChange = 0.0f;
                    if (animation.IsReversed)
                    {
                        if (animation.FrameIndex == 0)
                        {
                            animation.IsReversed = false;
                            ++animation.FrameIndex;
                        }
                        else
                        {
                            --animation.FrameIndex;
                        }
                    }
                    else
                    {
                        if (animation.FrameIndex == animation.Frames.Length - 1)
                        {
                            switch (animation.PlayMode)
                            {
                            case AnimationPlayMode.PlayOnce:
                                animation.IsPlaying = false;
                                break;

                            case AnimationPlayMode.PlayOnceReset:
                                animation.IsPlaying  = false;
                                animation.FrameIndex = 0;
                                break;

                            case AnimationPlayMode.Loop:
                                animation.FrameIndex = 0;
                                break;

                            case AnimationPlayMode.LoopReverse:
                                --animation.FrameIndex;
                                animation.IsReversed = true;
                                break;
                            }
                        }
                        else
                        {
                            ++animation.FrameIndex;
                        }
                    }

                    ImageComponent image = _imageMapper.Get(entity);
                    if (image != null)
                    {
                        FrameInfo frame = animation.Frames[animation.FrameIndex];
                        image.Source   = frame.Source;
                        image.Scale    = frame.Scale;
                        image.Rotation = frame.Rotation;
                        image.Tint     = frame.Tint;
                        image.Effects  = frame.Effects;
                        image.Origin   = new Microsoft.Xna.Framework.Vector2(frame.Source.Width / 2, frame.Source.Height / 2);
                    }
                }
                else
                {
                    animation.ElapsedTimeSinceLastFrameChange += ElapsedTimeSinceLastProcess;
                }
            }
        }