| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (18 out of 18)

Animating Icons

When any part of a class's icon description is given by an icon variable, you can use the conclude action to change the value of that icon variable for an instance of the class whenever G2 is running. The appearance of that instance changes to reflect the new value(s). Other instances of the class are unaffected. Changes to icon variable values are permanent: resetting the KB does not reset the value.

G2 performs type checking on all changes to icon variables, and signals an error if you attempt to conclude a value that is incompatible with the icon variable's usage.

Changing Width and Height

You cannot use icon variables to specify width and height because the width and height in an icon description are functionally icon variables already. Therefore, G2 lets you conclude values to them just as you can to icon variables that appear explicitly. This section hereafter refers to width and height as if they were ordinary icon variables.

When you change icon size by concluding values into width and height, the maximum allowable value for each dimension is 1000.

Referencing Icon Variables

Suppose that the icon description of the class Tank specifies:

If an instance of Tank named tank-1 exists, and none of these values has been changed by a conclude, the value of:

is:

Replacing Icon Variable Values

You can replace all icon variable values in a single operation by concluding a structure to them that specifies the new values. Thus:

sets tank-1's icon variables to have the values shown.

Merging Icon Variable Values

You can change some icon variable values while preserving the existing values of others. The technique is:

  1. Obtain the existing icon values

  2. Change values in the returned structure as desired.

  3. Conclude the changed structure back into the icon variables.

For example, if tank-1's icon variable values are:

then executing:

results in the icon variables of tank-1 being:

The same logic could be expressed more compactly as:

Alternatively, you can use a subattribute reference to conclude a single variable in the icon variable structure. Thus the effect of the preceding code could also be produced by executing:

This technique eliminates the overhead of explicitly retrieving, setting, and concluding values. However, a sequence of concludes that use subattribute references executes more slowly than a single conclude that accomplishes the effect of them all, and might cause icon appearance to pass through unwanted intermediate stages as the concludes execute one by one.

Conveniently Merging New and Default Values

When you want every icon variable to have either its class default value or a value to be set in a conclude action, you can conclude a structure that references only the icon variables that are to have non-default values.

For example, if the Tank class is as described under Referencing Icon Variables, and tank-2 has default values for all icon variables (width: 50, height: 50, x: 0, y: 0, z: 0), executing:

sets tank-2's icon variables to:

This technique eliminates the overhead of specifying icon variable values that are to be left unchanged, but it resets any icon variables not referenced in the concluded structure to have the default values specified for them in the class definition. For example, executing:

on the modified tank-2 sets tank-2's icon attributes to:

The value of z, being unspecified in the concluded structure, has reverted from 75 to the class default value.

| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (18 out of 18)

Copyright © 1997 Gensym Corporation, Inc.