Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Example / Listing] Draw a Line with a Certain Thickness (GM6)  (Read 3937 times)

0 Members and 1 Guest are viewing this topic.
[Example / Listing] Draw a Line with a Certain T...
« on: April 17, 2006, 01:39:48 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Unfortunately, line thickness was taken out of GM6. Luckily, this wil tell you how to put it back in. Basically, the fastest way to do this is to draw a stretched sprite.

First, create a sprite called "sprLine". It should be a 1x1, non-transparent, black pixel. Then, call this script whenever you want to draw a line with a certain thickness (in pixels)

Code: [Select]
//draw_line_thickness(x1,y1,x2,y2,thickness);
var thickness, startX, startY, endX, endY, tX;
startX = argument0;
startY = argument1;
endX = argument2;
endY = argument3;
thickness = argument4; //in pixels
tX = abs(endX - startX);
draw_sprite_ext(sprLine,0,startX,startY,tX,thickness,point_direction(startX,startY,endX,endY),c_white,1);


EDIT: THere is a slight glitch in this, and I'm working on it.
« Last Edit: February 24, 2012, 11:04:30 am by Niek »
Logged
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #1 on: April 17, 2006, 08:36:37 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Why was it taken out... And whats the glitch?
Logged
the a o d c
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #2 on: April 18, 2006, 12:13:27 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Taken out?

The glitch has to do with the image angle.
Logged

Ben

Re: Draw a Line with a Certain Thickness (GM6)
« Reply #3 on: April 18, 2006, 08:56:31 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Scooternew, I'm not entirely sure how draw_sprite_ext works, so forgive me if I'm asking the wrong questions.
But are you drawing the sprite over itself?
To be honest actually stretching the sprite repeatedly is just silly, so you might want to stretch/scale/roate whatever at the beginning, put it into a temp variable and delete it at the end, and instead of using draw_sprite_ext use draw_sprite.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #4 on: April 18, 2006, 11:30:48 pm »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Taken out?
Line thickness.

Ben, it doesnt draw twice, it only calls the draw function once.
Logged
the a o d c
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #5 on: April 18, 2006, 11:49:09 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
No, I'm not drawing the sprite over itself. I have an object draw a black pixel, but at a certain width and angle to give the impression of a thickenned line. Lin ethickness was taken out of GM6, and drawing primitives is slower than drawing a stretched sprite for this.

No, I'm not doing what you say...or using draw code more than once...

And darw_sprite_ext must be used to be able to edit the image angle.
Logged

Piers

Re: Draw a Line with a Certain Thickness (GM6)
« Reply #6 on: April 18, 2006, 11:51:19 pm »
This is something I can actually use. Thank you!
Logged
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #7 on: April 19, 2006, 01:09:23 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Scoot, try make a drawing font with outline :D
Logged
the a o d c
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #8 on: April 19, 2006, 04:42:34 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Drawing font with an outline...?

Can you explain?

If you want to be able to add an outline to a font, there are differnet ways.

You could have two fonts, the second being bigger than the first, and then drawing them on top fo each other to make an outline.

You could make a font sprite and use font_add_sprite, probably the best way and it leads to some amazing looking graphics.

You could draw transformed or colored text on itself to add the effect of outline.
Logged

mit

Re: Draw a Line with a Certain Thickness (GM6)
« Reply #9 on: April 19, 2006, 10:15:37 am »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
There's a draw_line thingy with variable thickness in my sig  :P

Not sure if it's slower, which it probably is, but it doesn't require a sprite, nor the registered version.
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #10 on: April 19, 2006, 11:03:01 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Not trying to sound "braggy" or something, but I assure you that the fastest way is to draw a stretched sprite.
Logged

mit

Re: Draw a Line with a Certain Thickness (GM6)
« Reply #11 on: April 20, 2006, 09:26:28 am »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Yeah, I'm aware it takes a lot more time, but it's useful for people who don't have the registered version, or whatever. And there's no glitches in it, although there's probably a fix to the one in yours.

EDIT: I was bored, and combined both of our scripts to achive a glitch-free and very fast line thickness script:
Code: [Select]
//draw_line_thickness(x1,y1,x2,y2,thickness);
var thickness, startX, startY, endX, endY, tX;
startX = argument0;
startY = argument1;
endX = argument2;
endY = argument3;
thickness = argument4; //in pixels
tX = point_distance(startX,startY,endX,endY)
draw_sprite_ext(sprLine,0,startX+lengthdir_x(thickness/2,point_direction(startX,startY,endX,endY)+90),startY+lengthdir_y(thickness/2,point_direction(startX,startY,endX,endY)+90),tX,thickness,point_direction(startX,startY,endX,endY),c_white,1);
draw_circle(startX,startY,thickness/2,0)
draw_circle(endX,endY,thickness/2,0)
« Last Edit: April 20, 2006, 09:37:52 am by mit »
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #12 on: April 20, 2006, 01:26:22 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 121
i tried both and the normal version works better but i also made another version including color

you need to make a pixel the same way as the other only white and call it sprLine2
Code: [Select]
//draw_line_thickness_ext(x1,y1,x2,y2,thickness,color,alpha);
var thickness, startX, startY, endX, endY, tX;
startX = argument0;
startY = argument1;
endX = argument2;
endY = argument3;
thickness = argument4; //in pixels
color = argument5
alpha = argument6
tX = point_distance(startX,startY,endX,endY)
draw_sprite_ext(sprLine2,0,startX+lengthdir_x(thickness/2,point_direction(startX,startY,endX,endY)+90),startY+lengthdir_y(thickness/2,point_direction(startX,startY,endX,endY)+90),tX,thickness,point_direction(startX,startY,endX,endY),color,alpha)

Logged

mit

Re: Draw a Line with a Certain Thickness (GM6)
« Reply #13 on: April 20, 2006, 03:15:55 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Rather than having an argument for the color it would be a lot easier for the user to just make it the draw color;
Code: [Select]
//draw_line_thickness(x1,y1,x2,y2,thickness);
var thickness, startX, startY, endX, endY, tX,color,alpha;
startX = argument0;
startY = argument1;
endX = argument2;
endY = argument3;
thickness = argument4; //in pixels
color = draw_get_color()
alpha = draw_get_alpha()
tX = point_distance(startX,startY,endX,endY)
draw_sprite_ext(sprLine2,0,startX+lengthdir_x(thickness/2,point_direction(startX,startY,endX,endY)+90),startY+lengthdir_y(thickness/2,point_direction(startX,startY,endX,endY)+90),tX,thickness,point_direction(startX,startY,endX,endY),color,alpha)

I think it looks nice with the circles on the ends, anyway.
« Last Edit: April 20, 2006, 03:18:00 pm by mit »
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Draw a Line with a Certain Thickness (GM6)
« Reply #14 on: April 20, 2006, 11:45:56 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
I fixed the script and I'll edit later.


WAIT: Oh, I didn't see the other posts. Well, I did something similar.

I like to be able to set the color during the script. Something like this:

draw_line_ext(x1,y1,x2,y2,thickness,color)

And you could easily work the color like this:

Code: [Select]
var drawCol, lineCol;
drawCol = draw_get_color();
draw_set_color(lineCol);
//draw line coding
draw_set_color(drawCol);

Well, I ditched the whole system out in favor of drawing with primitives, as lines are really just thin parallelograms.
« Last Edit: May 10, 2006, 08:50:35 pm by Scooternew »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.026 seconds with 64 queries.

anything