예제 #1
0
파일: Collider.cs 프로젝트: nikarh/Nez
 /// <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;
     }
 }
예제 #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);
            }
        }