コード例 #1
0
ファイル: DrawMap.cs プロジェクト: CarimA/RPG
        private void DrawEntities <T>(GameObjectList gameObjects) where T : COpacity
        {
            var mapObjects = gameObjects.All(typeof(CSprite), typeof(CAnimation), typeof(CPosition));

            foreach (var mapObject in mapObjects)
            {
                var sprite    = mapObject.Components.Get <CSprite>();
                var animation = mapObject.Components.Get <CAnimation>();
                var position  = mapObject.Components.Get <CPosition>();
                var opacity   = 1f;

                // todo: figure out a nice way of handling opacity when entities have both
                if (mapObject.Components.TryGet(out T op))
                {
                    opacity = op.Opacity != 0 ? op.Opacity : 1;
                }

                var positionVec = position.Position;
                if (mapObject.Components.TryGet(out CSize size))
                {
                    positionVec += (size.Size / 2);
                }

                _spriteBatch.Draw(sprite.Texture, positionVec,
                                  animation.GetFrame(), Color.White * opacity, 0, sprite.Origin, Vector2.One, SpriteEffects.None, 0f);
            }
        }