constraint

Usage

-- Lingo syntax
spriteObjRef.constraint

// JavaScript syntax
spriteObjRef.constraint;

Description

Sprite property; determines whether the registration point of a sprite is constrained to the bounding rectangle of another sprite (1 or TRUE) or not (0 or FALSE, default). Read/write.

The constraint 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 property affects moveable sprites and the locH and locV 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 property settings.

Example

This statement removes a constraint sprite property:

-- Lingo syntax
sprite(5).constraint = 0

// JavaScript syntax
sprite(5).constraint = 0;

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

-- Lingo syntax
sprite(i + 1).constraint = 14

// JavaScript syntax
sprite(i + 1).constraint = 14;

This statement checks whether sprite 3 is constrained and activates the handler showConstraint if it is:

-- Lingo syntax
if (sprite(3).constraint <> 0) then
   showConstraint
end if

// JavaScript syntax
if (sprite(3).constraint != 0) {
   showConstraint();
}

See also

locH, locV, Sprite