While the draw_circle_color function makes segments, this function can make any amount, allowing you to draw nearly perfect circles at any size.
The other script allows positioning a sound in 2D space without using the 3d sound commands.
Script
sound_set_position
// Usage: sound_set_position(sound, posX, posY, listenerX, listenerY, minrange, maxrange, minvolume, maxvolume, maxpan)
// argument 0, 1, 2, 3, 4, 5, 6, 7 8 9
// Parameters:
// * minrange: Distance from which on the sound has the full volume.
// * maxrange: Distance from which on the sound is not hearable anymore.
// * maxvolume: The maximum volume. Usually 1.
// This function/script allows adjusting a sound such that it gives the impression
// of originating from a position relative to the listener.
// This works only for one instance of the sound at a time (one-sound-per-position).
// All the functionality used for this is also available in the un-registered version of Game Maker,
// unlike the real 3D positional sound commands.
// Measure distance and calculate volume from this.
var distance, volume, difference;
distance = sqrt(sqr(argument3 - argument1) + sqr(argument4 - argument2));
if (distance > argument6)
volume = argument7;
else if (distance < argument5)
volume = argument8;
else
{
difference = argument6 - argument5;
volume = 1 - ((distance - argument5) / difference);
volume *= (argument8 - argument7);
volume += argument7;
}
// Calculate pan from angle
var pan;
pan = cos(point_direction(argument3, argument4, argument1, argument2) / 180 * pi);
pan *= argument9;
// Apply changes
sound_pan (argument0, pan);
sound_volume(argument0, volume);draw_circle_color_ext - Simple version
// Usage: draw_circle_color_ext(x, y, radius, col1, col2, alpha1, alpha2, outline, steps);
// This functionality is only available in the registered version of Game Maker.
// If we want only the outline, begin a linestrip...
if (argument7)
draw_primitive_begin(pr_linestrip);
else // ...otherwise a triangle fan
{
draw_primitive_begin(pr_trianglefan);
// Draw the center vertex.
draw_vertex_color(argument0, argument1, argument3, argument4);
}
// Draw the segments
var curAngle;
for (curAngle = 0; curAngle <= 360; curAngle += 360/argument8)
{
draw_vertex_color(argument0 + lengthdir_x(argument2, curAngle),
argument1 + lengthdir_y(argument2, curAngle),
argument4, argument5);
}
// Finish primitive
draw_primitive_end();draw_circle_color_ext - Version with 3 Colors (inner circle)
// Usage: draw_circle_color_ext(x, y, radius, innerRadiusPercentage, col1, col2, col3, alpha1, alpha2, alpha3, steps);
// 0 1 2 3 4 5 6 7 8 9 10
// This functionality is only available in the registered version of Game Maker.
// Color and alpha 1 are the inner colors.
// Color and alpha 2 and 3 are for the inner and outer circle.
// Inner circle
draw_primitive_begin(pr_trianglefan);
// Draw the center vertex.
draw_vertex_color(argument0, argument1, argument4, argument7);
var color, alpha, radius;
radius = argument2 * argument3; // inner radius
color = argument5;
alpha = argument8;
if (argument3 <= 0) // we can draw the outer "ring" right here if there's no inner circle.
{
radius = argument2;
color = argument6;
alpha = argument9;
}
// Draw the segments
var curAngle;
for (curAngle = 0; curAngle <= 360; curAngle += 360/argument10)
{
draw_vertex_color(argument0 + lengthdir_x(radius, -curAngle),
argument1 + lengthdir_y(radius, -curAngle),
color, alpha);
}
// Finish primitive
draw_primitive_end();
// Outer ring
if (argument3 >= 1) exit; // not visible
draw_primitive_begin(pr_trianglestrip);
for (curAngle = 0; curAngle <= 360; curAngle += 360/argument10)
{
draw_vertex_color(argument0 + lengthdir_x(radius, -curAngle),
argument1 + lengthdir_y(radius, -curAngle),
argument5, argument8);
draw_vertex_color(argument0 + lengthdir_x(argument2, -curAngle),
argument1 + lengthdir_y(argument2, -curAngle),
argument6, argument9);
}
draw_primitive_end();
Usage Samples
(no longer up to date with the current script)
- The following code, placed in the draw event of any object, draws a small red-green hexagon (looks like a circle):
draw_circle_color_ext(32, 32, 20, c_red, c_green, draw_get_alpha(), draw_get_alpha(), false, 16);
Download the script and demo project, GM 8 .gmk
includes a demo of sound_set_position, hotlink-hosted on Dropbox
I hope you'll find these useful.
-Paul
Edited by Master Xilo, 06 July 2012 - 12:57 PM.











