Jump to content


Photo

draw_circle_color_ext and sound_set_position


  • Please log in to reply
13 replies to this topic

#1 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 20 July 2006 - 06:38 PM

This script, which I quickly created in 5 minutes, allows drawing higher or lower detailed circles than the standard draw_circle_color function draws:
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
     


I hope you'll find these useful.

-Paul


Edited by Master Xilo, 23 August 2015 - 02:12 PM.

  • 1

#2 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 21 July 2006 - 03:01 PM

31 views but no comment???

Is this script not useful/helpful?

-thx
  • 0

#3 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 21 July 2006 - 03:37 PM

I haven't used it, but it's actually a decent idea at least, since I really hate it when I draw larger circles and ellipses and I see the segments.
  • 0

#4 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 22 July 2006 - 11:17 AM

I haven't used it, but it's actually a decent idea at least, since I really hate it when I draw larger circles and ellipses and I see the segments.

<{POST_SNAPBACK}>


That's why I wrote this script! <_<

Edited by Master Xilo, 26 October 2009 - 10:22 PM.

  • 0

#5 zmaj

zmaj

    GMC Member

  • GMC Member
  • 327 posts
  • Version:Unknown

Posted 03 October 2006 - 10:27 AM

That will be nice if you put some coment's

I mean, wrote what is argumen6 foe example for beginers...


Thanks!!
zmmaj
  • 0

zmmaj

Leader of ZmajSoft team at

http://www.zmajsoft.com

I-Goo creator and author at

http://i-goo.tk


#6 SanMan

SanMan

    GMC Member

  • New Member
  • 259 posts

Posted 03 October 2006 - 12:11 PM

That's actually pretty good. I could see this coming in handy.
  • 0

#7 Jesper

Jesper

    GMC Member

  • New Member
  • 1789 posts

Posted 03 October 2006 - 02:06 PM

I already made such a script. RegPoly Creator it was called I believe.
  • 0

The latest game news (Dutch): GameRSS game nieuws

#8 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 08 February 2011 - 05:36 PM

updated
  • 0

#9 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 08 February 2011 - 10:43 PM

Added an example:

Download the script and demo project, GM 8 .gmk
includes a demo of sound_set_position, hotlink-hosted on Dropbox


  • 0

#10 deformed thought

deformed thought

    GMC Member

  • GMC Member
  • 133 posts
  • Version:GM7

Posted 30 April 2011 - 01:02 AM

Isn't that just the same as draw_circle_ext()
but with draw_set_circle_precision() as well?
  • 1

#11 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 05 July 2011 - 08:41 AM

Well, the new draw_set_circle_precision() (which didn't exist at the time this script was written) indeed allows to make higher detailed circles with the built-in commands. But there's no way to draw a circle with different inner and outer transparency without this script.
  • 0

#12 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 07 July 2011 - 06:31 PM

Updated. Now supports an inner circle and 3 colors.
  • 0

#13 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 06 July 2012 - 01:14 PM

Added sound_set_position script here as that other post appears to have gone lost.
  • 1

#14 max_r_61270

max_r_61270

    GMC Member

  • New Member
  • 411 posts

Posted 01 November 2012 - 02:24 AM

Thank you for the sound effect script. I'm planning on using this kind of effect in my upcoming game and I was scratching my head, trying to figure out how to implement it. Now I know!
  • 0