User Guide

Chapter 3152
Examples
These statements check the constrainH function for sprite 1 when it has left and right
coordinates of 40 and 60:
put constrainH(1, 20)
-- 40
put constrainH(1, 55)
-- 55
put constrainH(1, 100)
-- 60
This statement constrains a moveable slider (sprite 1) to the edges of a gauge (sprite 2) when the
mouse pointer goes past the edge of the gauge:
set the locH of sprite 1 to constrainH(2, the mouseH)
See also
constrainV(), constraint, left, right
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.
Examples
This statement removes a constraint sprite property:
Dot syntax:
sprite(whichSprite).constraint = 0
Verbose syntax:
set the constraint of sprite whichSprite to 0
This statement constrains sprite (i + 1) to the boundary of sprite 14:
sprite(i + 1).constraint = 14
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