Asgard.Core.Physics.Midgard.CreateComponent C# (CSharp) Метод

CreateComponent() публичный Метод

public CreateComponent ( Artemis.Entity entity, BodyDefinition definition, bool remoteSync = true ) : Physics2dComponent
entity Artemis.Entity
definition BodyDefinition
remoteSync bool
Результат Asgard.EntitySystems.Components.Physics2dComponent
        public Physics2dComponent CreateComponent(Entity entity, BodyDefinition definition, bool remoteSync = true)
        {
            var body = CreateBody(definition);

            var component = new Physics2dComponent();
            component.Body = body;
            body.UserData = entity;
            entity.AddComponent(component);

            if (remoteSync)
            {
                ObjectMapper.Create(
                    (uint)entity.UniqueId, typeof(NetPhysicsObject));
            }

            return component;
        }

Usage Example

Пример #1
0
        public void Setup(Midgard world,  long ballId = 0)
        {
            var manager = world.EntityManager;
            if (ballId > 0)
            {
                _entity = manager.GetEntityByUniqueId(ballId);
                if (_entity == null)
                    _entity = manager.Create(ballId);
            }
            else
            {
                _entity = manager.Create();
            }

            var phyComp = world.CreateComponent(_entity, BodyDef);
            var body = phyComp.Body;

            CircleShape shape = new CircleShape(1,1);
            var fix = body.CreateFixture(shape);
            fix.Restitution = 1;
        }
All Usage Examples Of Asgard.Core.Physics.Midgard::CreateComponent