# nodesnim/nodes2d/collision_shape2d

Dark Mode

Search:
Group by:

It provides collision shapes.

# Imports

../thirdparty/opengl, ../core/vector2, ../core/rect2, ../core/anchor, ../core/input, ../core/enums, ../core/circle2, ../core/polygon2, ../nodes/node, node2d

# Types

    CollisionShape2DType {...}{.size: 1, pure.} = enum
      COLLISION_SHAPE_2D_RECTANGLE, COLLISION_SHAPE_2D_CIRCLE,
      COLLISION_SHAPE_2D_POLYGON

    CollisionShape2DObj = object of Node2DObj
      disable*: bool
      x1*, y1*, radius*: float
      polygon*: seq[Vector2Ref]
      shape_type*: CollisionShape2DType

    CollisionShape2DRef = ref CollisionShape2DObj

# Procs

    proc CollisionShape2D(name: string = "CollisionShape2D"): CollisionShape2DRef {...}{.
        raises: [], tags: [].}

  Creates a new CollisionShape2D.

  Arguments:

  - `name` is a node name.

  Examples:

      var node = CollisionShape2D("CollisionShape2D")

# Methods

    method setShapeTypeRect(self: CollisionShape2DRef) {...}{.base, raises: [], tags: [].}

  Changes shape type to `circle`.

    method setShapeTypeCircle(self: CollisionShape2DRef; cx, cy, radius: float) {...}{.base,
        raises: [], tags: [].}

  Changes shape type to `rectangle`.

  Arguments:

  - `cx` is a center circle position at X axis.
  - `cy` is a center circle position at Y axis.
  - `radius` is a circle radius.

    method setShapeTypePolygon(self: CollisionShape2DRef;
                              positions: varargs[Vector2Ref]) {...}{.base, raises: [],
        tags: [].}

  Changes shape type to `polygon`.

  Arguments:

  - `positions` is a varargs of polygon positions. Should be more than 2.

    method draw(self: CollisionShape2DRef; w, h: GLfloat) {...}{.raises: [], tags: [].}

  this method uses in the `window.nim`.

    method duplicate(self: CollisionShape2DRef): CollisionShape2DRef {...}{.base, raises: [],
        tags: [].}

  Duplicates CollisionShape2D object and create a new CollisionShape2D.

    method getGlobalMousePosition(self: CollisionShape2DRef): Vector2Ref {...}{.inline,
        raises: [], tags: [].}

  Returns mouse position.

    method isCollide(self: CollisionShape2DRef; x, y: float): bool {...}{.raises: [], tags: [].}

  Checks collision with point.

  Arguments:

  - `x` is a point position at X axis.
  - `y` is a point position at Y axis.

    method isCollide(self: CollisionShape2DRef; vec2: Vector2Ref): bool {...}{.raises: [],
        tags: [].}

  Checks collision with point.

    method isCollide(self, other: CollisionShape2DRef): bool {...}{.base, raises: [], tags: [].}

  Checks collision with other CollisionShape2D object.