protected override void OnDraw(GameTime gameTime, IEnumerable <int> entityIdCollection)
        {
            float ellapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            foreach (int liveId in entityIdCollection)
            {
                FrameAnimation animation = animationComponents.GetComponentFor(liveId);
                Aspect         aspect    = aspectComponents.GetComponentFor(liveId);

                int frameCount = spriteMapper.GetSpriteForId(aspect.ModelNameId).FrameCount;
                if (animation != null)
                {
                    float period = 1f / animation.FrameRate;
                    animation.EllapsedTime += ellapsed;
                    if (animation.EllapsedTime >= period)
                    {
                        animation.EllapsedTime -= period;
                        ChooseNextFrame(animation, aspect, frameCount);
                    }
                }
                else
                {
                    ChooseNextFrame(animation, aspect, frameCount);
                }
            }
        }
示例#2
0
        protected override void OnProcessEntities(GameTime gameTime, IEnumerable <int> entityIdCollection)
        {
            EntityManager em = this.EntityManager;

            for (int i = 0; i < textures.Length; i++)
            {
                textures[i].Clear();
            }

            foreach (int liveId in entityIdCollection)
            {
                Placement placement = placementComponents.GetComponentFor(liveId);
                Aspect    aspect    = aspectComponents.GetComponentFor(liveId);

                if (placement.Visible)
                {
                    int frameIndex   = aspect.FrameIndex;
                    int varietyIndex = aspect.VarietyIndex;

                    Sprite    sprite  = spriteMapper.GetSpriteForId(aspect.ModelNameId);
                    Texture2D texture = sprite.Texture;
                    Rectangle rect;
                    sprite.GetBounds(varietyIndex, frameIndex, out rect);
                    int framePixelWidth  = rect.Width;
                    int framePixelHeight = rect.Height;
                    int startPixelX      = rect.X;
                    int startPixelY      = rect.Y;

                    Color leColor = aspect.Tint;

                    TexAndPos texAndPos = new TexAndPos()
                    {
                        Size                = aspect.Size / framePixelWidth,
                        Texture             = texture,
                        Tint                = leColor,
                        Rotation            = MathHelper.ToRadians(placement.OrientationAngle + placement.AdditionalVisualOrientation),
                        StartEndSourceRectH = new Point(startPixelX, framePixelWidth),
                        StartEndSourceRectV = new Point(startPixelY, framePixelHeight),
                        SpriteEffects       = aspect.SpriteEffects
                    };
                    texAndPos.Position  = placement.Position;
                    texAndPos.Position += placement.AdditionalVisualPosition;

                    if (placement.Layer < textures.Length)
                    {
                        textures[placement.Layer].Add(texAndPos);
                    }
                }
            }
        }