Drawmethod is a series of properties OpenBOR applies to almost every element it draws to the screen. For instance, an entity might be drawn with alpha transparency and at 50% of its normal size. Drawmethod is actually applied at the drawing level (hence the name), but many OpenBOR elements have their own set of drawmethod properties to control the final drawmethod.
Native Access
Under construction
Script Access
Getting Drawmethods
void drawmethod = get_entity_property(void <entity pointer>, "drawmethod"));
Before you can access drawmethod properties, you need the drawmethod pointer. There are different ways to get these depending on the object in question. See the individual objects for details on how to access their drawmethod pointers. As an example, you can get the drawmethod property of an entity using the get_entity_property() function.
Common Drawmethod
void drawmethod = openborvariant("drawmethod_common");
Most direct draw script functions rely on a global common drawmethod. The pointer location for this drawmethod is read only, but you may modify its properties at will. The common drawmethod applies to all of the following:
- Drawbox()
- Drawboxtoscreen()
- Drawdot()
- Drawdottoscreen()
- Drawline()
- Drawlinetoscreen()
- Drawscreen()
- Drawsprite()
- Drawspritetoscreen()
Default Drawmethod
void drawmethod = openborvariant("drawmethod_default");
In order to provide default drawmethod properties, OpenBOR includes a hard-coded default drawmethod. You cannot modify the pointer or properties of this drawmethod in any way. If you try, a warning will be sent to the log and your attempt is ignored. The default drawmethod is available as a read only system variant.
Copy Drawmethod
void source_drawmethod = <value>;
void target_drawmethod = <value>;
copy_drawmethod(source_drawmethod , target_drawmethod);
For convenience, you can copy the values of one drawmethod structure directly to another.
Tip: Use the default drawmethod as a source to quickly reset all of a target drawmethod’s properties to their default values.
Allocate Drawmethod
void drawmethod = allocate_drawmethod();
OpenBOR script allows you to allocate your own drawmethod to memory, after which you may get and set its properties normally. This is especially useful for certain objects that do not normally have an independent drawmethod. For example, when any text is displayed it does not have its own drawmethod copy. Instead, its drawmethod pointer is set to the global drawmethod. This saves memory, but it also means you cannot normally modify the drawmethod properties of that text. But you can allocate a new drawmethod property and point the text’s drawmethod property to it, after which you are able to modify its properties at will.
Make sure you don’t lose the pointer so you can clear the allocated memory when you are finished, and only allocate drawmethods you need. Additionally, if the drawmethod pointer you replace DOES have its own independent drawmethod, you will need to be wary of its memory as well. Lastly, watch out for automated behaviors. For instance, if you allocate a new drawmethod and assign it to an entity, but that entity is then killed, OpenBOR will automatically destroy whatever drawmethod structure the entity’s drawmethod points to. If you aren’t paying attention, it’s possible to have odd situations such as an entity’s original drawmethod structure left floating around in memory while your created structure is gone!
Free (delete) Drawmethod
void drawmethod = <value>;
free(drawmethod);
As previously mentioned, always keep the pointer to drawmethods you allocate or detach, and free them when no longer needed. Otherwise the drawmethod structure stays in memory until the engine is shut down.
After the target drawmethod structure is deleted, its pointer is now “dangling”, meaning the part of memory it pointed to isn’t there any more, and the computer may allocate it to something else. Don’t try to use that pointer again, or you will get undefined behavior. Lastly, don’t try to free the global default drawmethod. At best, you will cause a shutdown.
Properties
Get a drawmethod property value.
mixed x = get_drawmethod_property(void <drawmethod pointer>, int <property>);
Modify a drawmethod property value.
mixed x = <value>;
set_drawmethod_property(void <drawmethod pointer>, int <property>, x);
Property List
- Constant: The property’s constant identifier.
- Type: The property value’s variable type.
- Description: A short description of what the property is and does.
| Constant | Type | Description |
|---|---|---|
| DRAWMETHOD_PROPERTY_ALPHA | Integer | Blending mode to apply. See gallery below for examples. * openborconstant("BLEND_MODE_ALPHA") – Lighter colors are more opaque. * openborconstant("BLEND_MODE_ALPHA_NEGATIVE") – Darker colors are more opaque. * openborconstant("BLEND_MODE_AVERAGE") – Averages each pixel against the pixel behind it, resulting in a default 50% transparency effect. You may control the averaging by color channel with channel properties. * openborconstant("BLEND_MODE_DODGE") – Severely increases contrast. * openborconstant("BLEND_MODE_HARDLIGHT") – Combines and reverses effects of Alpha and Negative Alpha blending. Uses a formula of bg > 128 ? multiply(bg*2,fg) : screen((bg-128)*2,fg). * openborconstant("BLEND_MODE_MODEL") – If the drawn item is an entity, use the entity’s alpha model property. * openborconstant("BLEND_MODE_NONE") – No blending (default). Unless an alpha mask is applied, the item will appear fully opaque. * openborconstant("BLEND_MODE_OVERLAY") – Combines effects of Alpha and Negative Alpha blending. Uses a formula of bg < 128 ? multiply(bg*2,fg) : screen((bg-128)*2,fg). |
| DRAWMETHOD_PROPERTY_CENTER_X | Integer | Adjusts location of the drawing point, and the center point for various draw effects ( rotation, shifting, etc.) along the horizontal axis. In the case of entities, the current animation frame offset is included. Default value is 0, starting at the far left of the current item image. |
| DRAWMETHOD_PROPERTY_CENTER_Y | Integer | Same as center_x, except along the vertical axis. |
| DRAWMETHOD_PROPERTY_CHANNEL_BLUE | Integer | When alpha is openborconstant("BLEND_MODE_AVERAGE"), this property controls opacity of the Blue color channel. Ranges are 0 (fully transparent) to 255 (default, fully opaque). Note: If all three channels are 255, the item will revert to 50% average for backward compatibility. |
| DRAWMETHOD_PROPERTY_CHANNEL_GREEN | Integer | Same as channel_blue, but for the Green color channel. |
| DRAWMETHOD_PROPERTY_CHANNEL_RED | Integer | Same as channel_blue, but for the Red color channel. |
| DRAWMETHOD_PROPERTY_CLIP_POSITION_X | Integer | Draw a clipped portion of the sprite, starting from the center axis. This property adjusts the starting horizontal position. |
| DRAWMETHOD_PROPERTY_CLIP_POSITION_Y | Integer | Adjust the vertical starting position for clipping. |
| DRAWMETHOD_PROPERTY_CLIP_SIZE_X | Integer | Horizontal size of the visible sprite area when clipping. |
| DRAWMETHOD_PROPERTY_CLIP_SIZE_Y | Integer | Vertical size of the visible sprite area when clipping. |
| DRAWMETHOD_PROPERTY_COLORSET_INDEX | Integer | For entities only. Draw the entity with one of its predefined color sets (palettes) by index. Essentially this property overrides the entity’s colorset_index property. * -1 (default) – Disabled. Entity uses its current colorset_index property. * 0 – Draw entity with its model’s default palette. * 1+ – Draw with alternate palettes 1, 2, … |
| DRAWMETHOD_PROPERTY_COLORSET_TABLE | Pointer | Pointer to the drawmethod color table. |
| DRAWMETHOD_PROPERTY_CONFIG | Integer | General config (on/off flags). Bitwise with following constants: * openborconstant("DRAWMETHOD_CONFIG_NONE") – No drawmethod config. Use to reset all flags to 0.* openborconstant("DRAWMETHOD_CONFIG_BACKGROUND_TRANSPARENCY") – Stage layers (bglayer, fglayer, background) and screens only. When set (default), the background color (first color table entry) is not drawn. Tip: It is less CPU intensive to draw the background color, so feel free to unset this flag when your visual design accommodates. * openborconstant("DRAWMETHOD_CONFIG_ENABLED") – If not set, drawmethod does not apply (global drawmethod used instead).* openborconstant("DRAWMETHOD_CONFIG_FLIP_ROTATE") – If set AND drawn element is an entity, rotation is reversed when the entity faces left.* openborconstant("DRAWMETHOD_CONFIG_FLIP_X") – Draw mirrored on horizontal axis.* openborconstant("DRAWMETHOD_CONFIG_FLIP_Y") – Draw mirrored on vertical axis. |
| DRAWMETHOD_PROPERTY_FILL_COLOR | Integer | Fills the drawn item with a solid color. Accepts an RGB color integer. For example, 16711680 is plain red. For simplicity, use the rgbcolor(red, green, blue) function to create your color integer. Tip: If you want to break a color integer back down to RGB components, just use a bit of math: int red = color_value / 256 / 256 / 256; int green = color_value / 256 % 256; int blue = color_value % 256; |
| DRAWMETHOD_PROPERTY_REPEAT_X | Integer | Stage layers only. Controls how many times the layer is drawn along horizontal axis. * -1 – Repeat layer infinitely. * 0 – Layer is not drawn at all. * 1+ – Draw layer once (default), twice, … |
| DRAWMETHOD_PROPERTY_REPEAT_Y | Integer | Same as repeat_x, except along vertical axis. Note: Native layer settings refer to this as zrepeat. This is due to game world design vs. what you see on a display screen. The layer appears to repeat along a lateral (Z) axis in game world, but of course display screens don’t have a lateral axis. The layer is actually being drawn repeated along the vertical axis of the display. |
| DRAWMETHOD_PROPERTY_ROTATE | Integer | Draw item with rotation from 0 (default) to 359 degrees clockwise around its offset. |
| DRAWMETHOD_PROPERTY_SCALE_X | Integer | Horizontal size. 256 (default) is the normal size. |
| DRAWMETHOD_PROPERTY_SCALE_Y | Integer | Vertical size. 256 (default) is the normal size. |
| DRAWMETHOD_PROPERTY_SHIFT_X | Integer | Skew the item along its horizontal axis. |
| DRAWMETHOD_PROPERTY_SPAN_X | Integer | Space in pixels between each subsequent draw repetition (see repeat_x) on the horizontal axis. |
| DRAWMETHOD_PROPERTY_SPAN_Y | Integer | Space in pixels between each subsequent draw repetition (see repeat_y) on the vertical axis. |
| DRAWMETHOD_PROPERTY_TAG | Integer | Tags are attributes not used in any way by engine logic. Employ this to store your own custom information about a drawmethod. Note: This feature is in progress and subject to change. |
| DRAWMETHOD_PROPERTY_TINT_COLOR | Integer | Similar to fill_color, but works in conjunction with tint_mode to apply a blended color overlay rather than an opaque fill. |
| DRAWMETHOD_PROPERTY_TINT_MODE | Integer | Transparency mode used to apply tint_color. Otherwise identical to alpha. |
| DRAWMETHOD_PROPERTY_WATER_MODE | Integer | Screens and level layers only. Applies a preset transformation. Originally intended to simulate water (hence the name), but useful for dozens of perspective or pseudo 3D effects. * openborconstant("WATER_MODE_NONE") – No water transformation (default). * openborconstant("WATER_MODE_SHEAR") – Apply shearing affine transformations, creating the illusion of a horizon bound landscape. Use water_size_begin, water_size_end, and water_perspective to adjust the effect. Often erroneously called “mode 7” after the eighth 0 indexed background mode of the Super NES. * openborconstant("WATER_MODE_SINE") – Apply repeating animated sine wave effect, giving the illusion of ripples. Adjust with water_wave_amplitude, water_wave_length, and water_wave_speed. |
| DRAWMETHOD_PROPERTY_WATER_PERSPECTIVE | Integer | Stretch or or tile when water_mode openborconstant(“WATER_MODE_SHEAR”) is enabled. The actual resulting effect will depend on size of image and other adjustments, so experiment. * openborconstant("WATER_PERSPECTIVE_NONE") – No perspective effect. * openborconstant("WATER_PERSPECTIVE_STRETCH") – Perspective with stretch. * openborconstant("WATER_PERSPECTIVE_TILE") – Perspective with tile. |
| DRAWMETHOD_PROPERTY_WATER_SIZE_BEGIN | Integer | Determines the beginning (top, assuming no rotation) size of a water_mode layer when openborconstant("WATER_MODE_SHEAR") is enabled. |
| DRAWMETHOD_PROPERTY_WATER_SIZE_END | Integer | Determines the ending (bottom, assuming no rotation) size of a water_mode layer when openborconstant("WATER_MODE_SHEAR") is enabled. |
| DRAWMETHOD_PROPERTY_WATER_WAVE_AMPLITUDE | Integer | Determines the amplitude (peak size of wave) when water_mode openborconstant("WATER_MODE_SINE") is enabled. |
| DRAWMETHOD_PROPERTY_WATER_WAVE_LENGTH | Integer | Determines the distance between wave peaks when water_mode openborconstant("WATER_MODE_SINE") is enabled. |
| DRAWMETHOD_PROPERTY_WATER_WAVE_SPEED | Integer | Animation speed of sine wave effect when water_mode openborconstant("WATER_MODE_SINE") is enabled. |
| DRAWMETHOD_PROPERTY_WATER_WAVE_TIME | Integer | Works in conjunction with water_wave_speed to control timing of animation when water_mode openborconstant("WATER_MODE_SINE") is enabled. |
| Constant | Type | Description |
Examples
Alpha






Clip


Rotate








Shift_x




Tint

Water Mode


Water Wave Amplitude


Legacy
Under construction