Difference between revisions of "Center.posn"

From AGI Wiki
Jump to navigationJump to search
(Created page with "The '''center.posn''' test command returns TRUE if the screen coordinates of the screen object's bottom center pixel is within a specified region. == Syntax == center.po...")
 
Line 18: Line 18:
 
== Possible Errors ==
 
== Possible Errors ==
  
AGI expects the coordinates to be in upper-left to lower-right format. X1 '''must''' be less than or equal to X2 and Y1 '''must''' be less than or equal to Y2, or the test will always fail.
+
AGI expects the coordinates to be in upper-left to lower-right format. '''X1''' ''must'' be less than or equal to '''X2''' and '''Y1''' ''must'' be less than or equal to '''Y2''', or the test will always fail.
  
 
== Example ==
 
== Example ==

Revision as of 19:20, 17 April 2019

The center.posn test command returns TRUE if the screen coordinates of the screen object's bottom center pixel is within a specified region.

Syntax

center.posn(obj oA, byt X1, byt Y1, byt X2, byt Y2)

Remarks

Test commands are only valid in an if statement.

The position test commands (posn, center.posn, right.posn, and obj.in.box are used to determine if a sceen object's position is within a certain area. The reference point for the center.posn command is the middle pixel of the screen object's baseline.

The region to be tested is bounded by (X1, Y1) - (X2, Y2). The test returns TRUE if the object's reference point is >= X1 AND <= X2 AND >= Y1 AND <= Y2.

This test command can be combined with the NOT operator to test if an object is NOT in a specified region.

Possible Errors

AGI expects the coordinates to be in upper-left to lower-right format. X1 must be less than or equal to X2 and Y1 must be less than or equal to Y2, or the test will always fail.

Example

Code:

<syntaxhighlight lang="agi"> if(center.posn(o1, 40, 120, 60, 130))

 { 
 print("the object's lower center pixel is in the box");
 }

</syntaxhighlight>

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 17 (0x11 hex)

See Also

Test Commands
posn
right.posn
obj.in.box