Esempio n. 1
0
        public void Draw(DrawInfo drawInfo)
        {
            var cameraPosition = (Vector2)drawInfo.State.CameraPosition;
            var layerOffsets   = drawInfo.State.DrawLayers.GetLayerOffsets();

            var grids = Subscribers.GetComponentsCompact();

            drawInfo.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, drawInfo.CameraTransform);

            for (var i = 0; i < grids.Length; i++)
            {
                DrawGrid(grids[i], drawInfo, cameraPosition, layerOffsets);
            }

            drawInfo.SpriteBatch.End();
        }
Esempio n. 2
0
        //private void ExtendLayersToElement(int lastLayerIndex)
        //{
        //    int?[] oldArray = LayerSeperatingIndices ?? new int?[0];
        //    LayerSeperatingIndices = new int?[lastLayerIndex + 1];

        //    for (int i = 0; i < LayerSeperatingIndices.Length; i++)
        //    {
        //        LayerSeperatingIndices[i] = i < oldArray.Length ? oldArray[i] : null;
        //    }
        //}

        //private int GetInsertIndex(int layerIndex)
        //{
        //    if (layerIndex == LayerSeperatingIndices.Length - 1)
        //    {
        //        return subbedEntities.Count;
        //    }
        //    else
        //    {
        //        for (int i = layerIndex + 1; i < LayerSeperatingIndices.Length; i++)
        //        {
        //            if (LayerSeperatingIndices[i] != null)
        //            {
        //                return (int)LayerSeperatingIndices[i];
        //            }
        //        }

        //        throw new InvalidOperationException("layerSeperatingIndices' final element is null and not the only element in the array.");
        //    }
        //}

        //private void UpdateLayerSeperatingIndices(int insertIndex, int layerIndex)
        //{
        //    if (LayerSeperatingIndices[layerIndex] == null)
        //    {
        //        if (layerIndex == LayerSeperatingIndices.Length - 1)
        //        {
        //            LayerSeperatingIndices[layerIndex] = subbedEntities.Count - 1;
        //            return;
        //        }
        //        else
        //        {
        //            LayerSeperatingIndices[layerIndex] = insertIndex;
        //        }
        //    }

        //    for (int i = layerIndex + 1; i < LayerSeperatingIndices.Length; i++)
        //    {
        //        LayerSeperatingIndices[i]++;
        //    }
        //}

        //public override void AddComponent(int entity, GameState state)
        //{
        //    int layerIndex = state.GetComponentOfEntity<Drawable>(entity).DrawLayer;
        //    if (LayerSeperatingIndices == null || layerIndex >= LayerSeperatingIndices.Length)
        //    {
        //        ExtendLayersToElement(layerIndex);
        //    }

        //    int insertIndex = GetInsertIndex(layerIndex);
        //    subbedEntities.Insert(insertIndex, entity);
        //    UpdateLayerSeperatingIndices(insertIndex, layerIndex);

        //    OnAddEntity(entity, state);
        //}

        public void Draw(DrawInfo drawInfo)
        {
            var layerOffsets = new Vector2[drawInfo.State.DrawLayers.Count];

            for (var i = 0; i < layerOffsets.Length; i++)
            {
                layerOffsets[i] = drawInfo.State.DrawLayers[i].DrawOffset;
            }

            drawInfo.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, drawInfo.CameraTransform);

            var sprites = Subscribers.GetComponentsCompact();

            for (var i = 0; i < sprites.Length; i++)
            {
                DrawSprite(sprites[i], drawInfo, layerOffsets);
            }

            drawInfo.SpriteBatch.End();
        }