Difference between revisions of "Add.to.pic"

From AGI Wiki
Jump to navigationJump to search
m (Collector moved page Add.to.pic to Add.to.pic();)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''add.to.pic''' command draws a [[Cel|cel]] from a [[VIEW Resource|view]] to the [[visual picture screen]] in memory. There is an [[indirect]] version of this command called '''add.to.pic.v'''.
+
[[Category:AGI Pages]]
 +
The '''add.to.pic''' command allows you to add a view to the visual picture screen in memory.
  
<code>add.to.pic(viewNumber, loopNumber, celNumber, x, y, priority, margin);</code>
+
== Syntax ==
  
Cel <code>celNumber</code> of [[loop]] <code>loopNumber</code> of VIEW viewNumber is drawn on the [[Picture Resource|picture]] at position (x, y) with a [[priority]] of <code>priority</code>. If margin is 0, 1, 2, or 3, the base line of the [[object]] (the bottom row of pixels of the cel) is given a priority of <code>margin</code>. Since priority is taken into account, you can use <code>add.to.pic</code> to add cels behind other parts of the picture.
+
add.to.pic([[number|byt]] VIEW, [[number|byt]] LOOP, [[number|byt]] CEL, [[number|byt]] X, [[number|byt]] Y, [[number|byt]] PRI, [[number|byt]] MGN);
  
Note that the VIEW must be [[loaded]] before you use it with <code>add.to.pic</code>.
+
== Remarks ==
  
==Parameters==
+
[[Cel]] CEL of [[loop]] LOOP of [[view]] VIEW is drawn on the picture at X, Y with a [[priority]] of PRI. The priority argument can be used to add views behind other parts of the picture.
  
===For add.to.pic===
+
The location is validated by AGI to ensure the [[view]] is not added so that any part of it is off the screen. It does this by using the [[Animated Object#Shuffling|shuffling]] method for screen object placement, but ignores other objects and the [[horizon]].
  
* <code>viewNumber</code>: a number, 0-255, specifying the [[VIEW Resource|view resource]] that contains the cel that should be drawn
+
If PRI is zero, the priority is set automatically according to the view's Y value. Use a PRI value of 3 through 15 to force the priority to a specific value. If the PRI value is 1 or 2, the view won't show on the visual screen but the view's control line box (if MGN argument is 0, 1, 2, or 3) will still be drawn.
* <code>loopNumber</code>: a number, 0-255, specifying the loop in the VIEW resource that contains the cel that should be drawn
 
* <code>celNumber</code>: a number, 0-255, specifying the cel that should be drawn
 
* <code>x</code>: a number, 0-255, specifying the x position where the cel should be drawn
 
* <code>y</code>: a number, 0-255, specifying the y position where the cel should be drawn
 
* <code>priority</code>: a number, 0-15, specifying the priority that should be assigned to the cel when it is drawn; '''note:''' after the cel is drawn, the priority cannot be changed
 
* <code>margin</code>: a number, 0-3, specifying the priority of the base line of the object (the bottom row of pixels of the cel); this parameter can be used, for example, to prevent ego from walking through the cel, making it appear to be a solid object on the screen
 
  
 +
Use the MGN property if you want the added view to include a control box. If MGN is 0, 1, 2 or 3, AGI draws a box on the priority screen. The box is drawn so the bottom line is on the view's bottom row, and the top line is on the last row that has the same priority. So if you add a view with a Y position at the bottom of a priority band you'll get a taller box than if you add it near the top of a band. If you position it on the top row of a priority band, you'll get a line instead of a box.
  
===For add.to.pic.v===
+
Unless the view resource is needed for something else, you should [[discard.view|discard]] it after adding it to the picture, in order to limit [[memory]] usage.
 +
AGI adds a script entry to the [[script stack]] each time '''add.to.pic''' is executed.
  
* <code>viewNumber</code>: a [[variable]], v0-v255, whose value specifies the VIEW resource that contains the cel that should be drawn
+
== Possible Errors ==
* <code>loopNumber</code>: a variable, v0-v255, whose value specifies the loop in the VIEW resource that contains the cel that should be drawn
+
If the LOOP value does not point to a valid [[loop]], AGI raises [[trappable error]] #6.
* <code>celNumber</code>: a variable, v0-v255, whose value specifies the cel that should be drawn
 
* <code>x</code>: a variable, v0-v255, whose value specifies the x position where the cel should be drawn
 
* <code>y</code>: a variable, v0-v255, whose value specifies the y position where the cel should be drawn
 
* <code>priority</code>: a variable, v0-v255, whose value specifies the priority that should be assigned to the cel when it is drawn; '''note:''' after the cel is drawn, the priority cannot be changed
 
* <code>margin</code>: a variable, v0-v255, whose value specifies the priority of the base line of the object (the bottom row of pixels of the cel); this parameter can be used, for example, to prevent ego from walking through the cel, making it appear to be a solid object on the screen
 
  
 +
Try to make sure you limit your values for PRI and MGN arguments to less then or equal to 15. If you don't, you may get unexpected results; AGI uses the following formula for calculating the actual values for PRI and MGN based on the passed argument values:<br />
 +
<code>PRI(actual) = PRI(argument) AND 0x0F<br />
 +
MGN(actual) = PRI(argument)>>4 OR (MGN(argument) AND 0x0F)</code><br />
  
==Possible errors==
+
Do '''not''' use cels with widths less than three pixels if you want to draw a control box; AGI's algorithm to draw the control box has a bug in it that draws a line across the entire screen if width is 1 or crashes the game if width is 2.
  
* if the specified VIEW has not yet been loaded (see [[load.view]]), then the game will crash with a [[view not loaded error]]
+
The [[view]] must be [[load.view|loaded]] before you use it with '''add.to.pic''' or AGI will raise [[trappable error]] #3. Use the '''[[load.view]]''' command to load a view.
* every time the add.to.pic or add.to.pic.v command is issued, it adds to the [[Script Buffer|script buffer]]; this can lead to a [[Script Buffer Overflow Error|script buffer overflow error]]
 
  
 
+
== Example ==
==Example==
 
 
 
The following example uses add.to.pic to draw cel 3 from loop 2 of VIEW 15 at position (40, 120) with a priority of 9 and a margin of 0 ([[Unconditional Barrier|unconditional barrier]]).
 
 
 
<code>load.view(15);
 
add.to.pic(15, 2, 3, 40, 120, 9, 0);</code>
 
 
 
The next example uses the [[Indirect Command|indirect command]] <code>add.to.pic.v</code> to accomplish the same thing:
 
  
 
<div class="CodeBlockHeader">Code:</div>
 
<div class="CodeBlockHeader">Code:</div>
 
<syntaxhighlight lang="agi">
 
<syntaxhighlight lang="agi">
load.view(15);
+
load.view(9); [ ensure view is loaded
 +
add.to.pic(9, 0, 0, 20, 120, 14, 2);
 +
[  first cel of first loop of view 9
 +
[  is added to current picture at position (20, 120)
 +
[  with priority 14, and an alarm line (MARGIN = 2)
 +
[  is drawn along bottom row of the cel on the priority screen
  
v200 = 15;
+
discard.view(9); [ discard view after adding it
v201 = 2;
+
</syntaxhighlight>
v202 = 3;
 
v203 = 40;
 
v204 = 120;
 
v210 = 9;
 
v215 = 0;
 
  
add.to.pic.v(v200, v201, v202, v203, v204, v210, v215);
+
== Technical Information ==
</syntaxhighlight>
 
  
==Sources==
+
{| border="1" cellpadding="2"
 +
| style="background-color: #efefef" width="200" | '''Required Interpreter Version:'''
 +
| width="175" | Available in all AGI versions.
 +
|-
 +
| style="background-color: #efefef" | '''Byte-Code Value:'''
 +
| 122 (0x7A hex)
 +
|}
  
Some of the content of this page was taken from the [[AGI Studio]] help file.
+
== See Also ==
  
&nbsp;
+
* [[Screen Objects/View Commands]]
 +
* '''[[add.to.pic.v]]'''
  
[[Category:Logic Commands]]
+
[[Category:Commands]]
[[Category:Object and VIEW Commands]]
 

Latest revision as of 13:57, 28 January 2022

The add.to.pic command allows you to add a view to the visual picture screen in memory.

Syntax

add.to.pic(byt VIEW, byt LOOP, byt CEL, byt X, byt Y, byt PRI, byt MGN);

Remarks

Cel CEL of loop LOOP of view VIEW is drawn on the picture at X, Y with a priority of PRI. The priority argument can be used to add views behind other parts of the picture.

The location is validated by AGI to ensure the view is not added so that any part of it is off the screen. It does this by using the shuffling method for screen object placement, but ignores other objects and the horizon.

If PRI is zero, the priority is set automatically according to the view's Y value. Use a PRI value of 3 through 15 to force the priority to a specific value. If the PRI value is 1 or 2, the view won't show on the visual screen but the view's control line box (if MGN argument is 0, 1, 2, or 3) will still be drawn.

Use the MGN property if you want the added view to include a control box. If MGN is 0, 1, 2 or 3, AGI draws a box on the priority screen. The box is drawn so the bottom line is on the view's bottom row, and the top line is on the last row that has the same priority. So if you add a view with a Y position at the bottom of a priority band you'll get a taller box than if you add it near the top of a band. If you position it on the top row of a priority band, you'll get a line instead of a box.

Unless the view resource is needed for something else, you should discard it after adding it to the picture, in order to limit memory usage. AGI adds a script entry to the script stack each time add.to.pic is executed.

Possible Errors

If the LOOP value does not point to a valid loop, AGI raises trappable error #6.

Try to make sure you limit your values for PRI and MGN arguments to less then or equal to 15. If you don't, you may get unexpected results; AGI uses the following formula for calculating the actual values for PRI and MGN based on the passed argument values:
PRI(actual) = PRI(argument) AND 0x0F
MGN(actual) = PRI(argument)>>4 OR (MGN(argument) AND 0x0F)

Do not use cels with widths less than three pixels if you want to draw a control box; AGI's algorithm to draw the control box has a bug in it that draws a line across the entire screen if width is 1 or crashes the game if width is 2.

The view must be loaded before you use it with add.to.pic or AGI will raise trappable error #3. Use the load.view command to load a view.

Example

Code:

<syntaxhighlight lang="agi"> load.view(9); [ ensure view is loaded add.to.pic(9, 0, 0, 20, 120, 14, 2); [ first cel of first loop of view 9 [ is added to current picture at position (20, 120) [ with priority 14, and an alarm line (MARGIN = 2) [ is drawn along bottom row of the cel on the priority screen

discard.view(9); [ discard view after adding it </syntaxhighlight>

Technical Information

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

See Also