Lingo Dictionary > A-C > constraint |  |

constraint

Syntax

    sprite(whichSprite).constraint
    the constraint of sprite whichSprite

Description

Sprite property; determines whether the registration point of the sprite specified by `whichSprite` is constrained to the bounding rectangle of another sprite (1 or `TRUE`) or not (0 or `FALSE`, default).

The `constraint` sprite property is useful for constraining a moveable sprite to the bounding rectangle of another sprite to simulate a track for a slider control or to restrict where on the screen a user can drag an object in a game.

The `constraint` sprite property affects moveable sprites and the `locH` and `locV` sprite properties. The constraint point of a moveable sprite cannot be moved outside the bounding rectangle of the constraining sprite. (The constraint point for a bitmap sprite is the registration point. The constraint point for a shape sprite is its top left corner.) When a sprite has a constraint set, the constraint limits override any `locH` and `locV` sprite property settings.

This property can be tested and set.

Example

This statement removes a `constraint` sprite property:

Dot syntax:

    sprite(whichSprite).constraint = 0

Verbose syntax:

    set the constraint of sprite whichSprite to 0

Example

This statement constrains sprite (i + 1) to the boundary of sprite 14:

    sprite(i + 1).constraint = 14

Example

This statement checks whether sprite 3 is constrained and activates the handler `showConstraint` if it is: (The operator `<>` performs a not-equal-to operation.)

    if sprite(3).constraint <> 0 then showConstraint

See also

`constrainH()`, `constrainV()`, `locH`, `locV`