<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/SKConstraint/positionX(_:y:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKConstraint(cm)positionX:Y:"
  },
  "title" : "positionX(_:y:)"
}
-->

# positionX(_:y:)

Creates a constraint that restricts both coordinates of a node’s position.

```
class func positionX(_ xRange: SKRange, y yRange: SKRange) -> Self
```

## Parameters

`xRange`

The range to restrict the x-coordinate to.

`yRange`

The range to restrict the y-coordinate to.

## Return Value

A new constraint.

## Discussion

Each time constraints are applied, the node’s [`position`](/documentation/SpriteKit/SKNode/position) property is clamped so that both coordinates lie inside the specified ranges.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)