addCollider() public static method

adds the collider to the physics system
public static addCollider ( Collider collider ) : void
collider Collider Collider.
return void
示例#1
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);
            }
        }
示例#2
0
文件: Collider.cs 项目: Pyxlre/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 proper such as origin are changed before we are added to an Entity
     if (_isParentEntityAddedToScene)
     {
         Physics.addCollider(this);
     }
 }
示例#3
0
        void addColliders()
        {
            if (_collisionLayer == null)
            {
                return;
            }

            // fetch the collision layer and its rects for collision
            var collisionRects = _collisionLayer.getCollisionRectangles();
            var renderPosition = entity.transform.position + _localPosition;

            // 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 + renderPosition.X, collisionRects[i].Y + renderPosition.Y, collisionRects[i].Width, collisionRects[i].Height);
                collider.entity = entity;
                _colliders[i]   = collider;

                Physics.addCollider(collider);
            }
        }