Skip to content

OutlineObject and OutlineObjectBaked

Grisgram edited this page May 18, 2023 · 9 revisions

Object hierarchy

OutlineObjectBaked is a child object of OutlineObject, so they share the same variable definitions and behave identical.

Details about the difference (in other words: What does OutlineObjectBaked offer more than OutlineObject?) a bit below.

Variable definitions

Both of these objects implement an outline_drawer and offer these instance variables:

image

Variable Default Description
draw_on_gui false If set, the object will draw in the Draw GUI event instead of Draw
outline_color c_white The color of the outline to draw
outline_alpha 1 Starting alpha value of the outline
outline_alpha_fading true If set, the outline will fade to transparent and not end aprupt
outline_strength 3 Thickness of the outline.
NOTE: For performance reasons, the maximum strength of an outline is 10.
Higher values will be ignored, and strength 10 gets drawn
outline_always false If set, the object will always be drawn outlined, no matter what.
Activating this, will cause the outline_on_mouse_over to be ignored
outline_on_mouse_over true If set, the object will only be drawn outlined, when the mouse touches it
use_bbox_of_sprite false If set, the bbox (collision mask) of the sprite will be used to determine the outline area to draw.
See below for detailled explanation
pulse_active false If set, the next three variables will become active. You can create animated flashing effects with those
pulse_min_strength
pulse_max_strength
0 Min/Max strength of the outline while pulsating
pulse_color_1
pulse_color_2
c_white The starting/final color of the color pulse
pulse_frequency_frames 0 The number of frames for the pulse.
This is the time, the pulse effect will need to go min->max->min
(Or color_1->color_2->color_1 for color pulse)

use_bbox_of_sprite

This setting needs a bit explanation. By default, the OutlineDrawer will use the entire frame size of the sprite to render the outline. However, this fails, when you start rotating or zooming or otherwise manipulating the sprite, because it will always consider only the "base" dimensions of the frame.

On the other hand, sometimes the bbox is not as large as the entire sprite, sometimes it is only a very small area that shall be checked for collision. Using the bbox makes no sense then, as it would outline only that small portion.

Depending on what you do with the sprite at runtime, you should turn this off or on. Roating/Zooming things should have it on. Sprites that only move, but don't rotate or zoom, should turn it off.

Alpha fading and pulse

Here are some images that show you how those effects look

No alpha fading Active alpha fading
image image
Pulse with strength Pulse with color
pulse-shader-strength pulse-shader-color

Of course, those effects can be combined and you may create a strength + color pulse!

OutlineObjectBaked

This object allows "pre-baking" of the outline effect, which means, upon creation it will render all frames of the sprite to a surface with the outline already applied. This makes creating such an object a bit slower, but gives you in return a huge performance increase when you activate the outline drawing, as the shader will not get active. All the outlines have already been drawn.

In case, you change the sprite of the object at runtime and want to "bake it again" with the new sprite, this object offers a bake() method, which needs no parameters. It will pre-bake the currently assigned sprite to the surface. Remember, that baking may take some milliseconds, depending on the size of the sprite and the number of frames.

Code

The Create event initializes the object based on the instance variables set and also declares a mouse_is_over variable that will be set in the Mouse Enter and Mouse Leave events.

outliner = new outline_drawer(0, outline_color, outline_alpha, outline_strength, outline_alpha_fading);
mouse_is_over = false;

The Draw event finally launches the outline drawing:

if (outline_on_mouse_over && mouse_is_over)
	outliner.draw_object_outline();
else
	draw_self();
	

You see, it is as easy as a handful lines of code to activate outlining for any of your objects. The real magic happens of course in the outline_drawer and the shader itself.

For you, as the end user of these objects, this means, that you can simply drag one of these to your scene and are done!