# icon object

Source: https://ref.dm-lang.org/icon/

An `/icon` object is created by loading an icon file into memory for direct access and manipulation. In order to be displayed, an `/icon` object always gets converted back into an icon file; this happens automatically when you assign atom.icon to an `/icon` object, since that variable may only refer to a static icon file, rather than a dynamic memory object.

To create an `/icon` object, simply use `new/icon()`, or the short-cut `icon()` proc. The following example loads an icon file, reddens it, and then assigns it back to the player's icon, which implicitly creates a new icon file.

```dm
mob/verb/test()
   var/icon/I = new('player.dmi')
   I.Blend(rgb(40,0,0))
   usr.icon = I
```

Note that merely displaying different icon states or directions can generally be achieved without any icon manipulation, which saves quite a bit of overhead. For example, the variables `atom.icon_state` and `atom.dir` can be used to control how `atom.icon` is displayed, without any need for generating a new icon file.

Many things that used to require icon manipulation may not need you to do so anymore, as DM has evolved new capabilities.

|             Operation             |                                `/icon` proc                                |                                                  New method                                                  |
|-----------------------------------|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
|       Multiplying by color        |[`Blend`](https://ref.dm-lang.org/icon/proc/Blend.md) or [SetIntensity](https://ref.dm-lang.org/icon/proc/SetIntensity.md) procs|                                         [color](https://ref.dm-lang.org/atom/var/color.md) var                                         |
|           Adding color            |                       [Blend](https://ref.dm-lang.org/icon/proc/Blend.md) proc                       |                   [color](https://ref.dm-lang.org/atom/var/color.md) var (using [color matrix](https://ref.dm-lang.org/notes/color-matrix.md))                   |
|       Applying color matrix       |                   [MapColors](https://ref.dm-lang.org/icon/proc/MapColors.md) proc                   |                                                                                                              |
|             Rotation              |                        [Turn](https://ref.dm-lang.org/icon/proc/Turn.md) proc                        |                                     [transform](https://ref.dm-lang.org/atom/var/transform.md) var                                     |
|   Flipping horizontal/vertical    |                        [Flip](https://ref.dm-lang.org/icon/proc/Flip.md) proc                        |                                                                                                              |
|              Scaling              |                       [Scale](https://ref.dm-lang.org/icon/proc/Scale.md) proc                       |                                                                                                              |
|Overlaying/underlaying another icon|              [Blend](https://ref.dm-lang.org/icon/proc/Blend.md) proc + `ICON_OVERLAY`              |Overlay/underlay + [KEEP_TOGETHER](https://ref.dm-lang.org/atom/var/appearance_flags.md)  <br/>[Layering filter](https://ref.dm-lang.org/notes/filters/layer.md)|

> [!note]
> 
> Anything you can do with an atom var instead of using icon manipulation procs will usually perform much better. Games that use the new methods use fewer resources, use less memory, and also usually look better too.

### See also
- [procs (icon)](https://ref.dm-lang.org/icon/proc/index.md)
- [icons](https://ref.dm-lang.org/DM/icon/index.md)
- [image objects](https://ref.dm-lang.org/image/index.md)
- [stddef.dm file](https://ref.dm-lang.org/appendix/stddefdotdm.md)

## Pages

- [procs (icon)](https://ref.dm-lang.org/icon/proc/index.md)
