Reposition
The reposition command changes the position of a screen object currently drawn on the screen by an amount relative to its current position.
Syntax
reposition(obj oA, var vDX, var vDY);
Remarks
The position of screen object oA is changed to (X + vDX, Y + vDY) where X and Y are its current coordinates. The values of vDX and vDY are treated as 8 bit signed numbers (values >= 128 are negative numbers, i.e. 255 = -1, 254 = -2, etc.) Mathematically this is represented as delta = value - 256
.
The new location is validated using the shuffle function.
The WinAGI compiler allows negative numbers to be assigned to variables to facilitate use of the reposition command. The negative number is automatically converted to the correct unsigned 8-bit value. Other AGI compilers may not support this feature.
The reposition command erases the screen object from its old location before redrawing it in its new location.
This command can be executed on a screen object that has been initialized but not yet drawn. In this case it will reposition the object without redrawing it.
Use the reposition.to and reposition.to.v commands to change an object's position using absolute coordinates.
Possible Errors
AGI does not check that object number oA is a valid screen object. If it is not, this command will overwrite other data on the memory heap, which may cause unexpected results, including possibly crashing AGI.
Example
<syntaxhighlight lang="agi"> [ move an object down 32 pixels, over 8 pixels v255 = 8; v201 = 0; v201 = v201 - v255; [ convert to negative value v255 = 32; v202 = 0; v202 = v202 - v255; [ convert to negative value reposition(o4, v201, v202); [ make the move
[ in WinAGI you can do this: v201 = -8; v202 = -32; reposition(o4, v201, v202); </syntaxhighlight>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 40 (0x28 hex) |