Beispiel #1
0
 /// <summary>
 /// the parent Entity will call this at various times (when added to a scene, enabled, etc)
 /// </summary>
 public virtual void RegisterColliderWithPhysicsSystem()
 {
     // entity could be null if properties such as origin are changed before we are added to an Entity
     if (_isParentEntityAddedToScene && !_isColliderRegistered)
     {
         Physics.AddCollider(this);
         _isColliderRegistered = true;
     }
 }
Beispiel #2
0
        public void AddColliders()
        {
            if (CollisionLayer == null || !_shouldCreateColliders)
            {
                return;
            }

            // fetch the collision layer and its rects for collision
            var collisionRects = CollisionLayer.GetCollisionRectangles();

            // create colliders for the rects we received
            _colliders = new Collider[collisionRects.Count];
            for (var i = 0; i < collisionRects.Count; i++)
            {
                var collider = new BoxCollider(collisionRects[i].X + _localOffset.X, collisionRects[i].Y + _localOffset.Y, collisionRects[i].Width, collisionRects[i].Height);
                collider.PhysicsLayer = PhysicsLayer;
                collider.Entity       = Entity;
                _colliders[i]         = collider;

                Physics.AddCollider(collider);
            }
        }