how to draw a line in game
by Steven Sheffey · in Torque Game Builder · 12/04/2009 (9:00 pm) · 7 replies
Hi all, I've been trying to find a way to either use a scene object or mouse to draw a line in game. I would like it to be free form so that the draw line will move in any direction depending on the objects position. Ive read other threads about stretching and image the length you need, but obviously that wouldn't work in this case as you cant curve it.
If someone could point me in the right direction or have any suggestions please through it there, I believe others would like to get some info on this as well.
Thanks,
Steven
If someone could point me in the right direction or have any suggestions please through it there, I believe others would like to get some info on this as well.
Thanks,
Steven
#2
www.thisismyurl.com/torque/code-free-pong/
Just look for the files and follow the directions to make the paddles. It will make a very basic line for you.
12/05/2009 (1:11 pm)
I think this will help you out in making a line.www.thisismyurl.com/torque/code-free-pong/
Just look for the files and follow the directions to make the paddles. It will make a very basic line for you.
#3
@Pubily
Great tutorial and I was able to learn some things from your post :)
@William and @Pubily
Sorry, let me clarify. Right now I'm playing around with a ship using the asteroid behavior thruster controls. I have enemy ships that move around and my goal was to take my ship and fly a circle around them and enclosing them in a circle. I was thinking that a scribble line could be drawn from my ship based on its position and also have collision so that the enemy ship will be trapped.
So you fly around and when you encounter an enemy ship you would hold down a button and that will say to draw the scribble line while you try to wrap around the enemy. In my head the only way to do something like this would be to spawn tiny sceneObjects using onUpdate and add collision to all of them but that seems like a dangerous way to go performance wise.
Hope that gives a little more clarity on my goal. Thanks again for any suggestions!
12/06/2009 (4:21 am)
Hey guys, thanks for the replies. @Pubily
Great tutorial and I was able to learn some things from your post :)
@William and @Pubily
Sorry, let me clarify. Right now I'm playing around with a ship using the asteroid behavior thruster controls. I have enemy ships that move around and my goal was to take my ship and fly a circle around them and enclosing them in a circle. I was thinking that a scribble line could be drawn from my ship based on its position and also have collision so that the enemy ship will be trapped.
So you fly around and when you encounter an enemy ship you would hold down a button and that will say to draw the scribble line while you try to wrap around the enemy. In my head the only way to do something like this would be to spawn tiny sceneObjects using onUpdate and add collision to all of them but that seems like a dangerous way to go performance wise.
Hope that gives a little more clarity on my goal. Thanks again for any suggestions!
#4
For a quick test, you might just create a bouncing ball. Then have the program create random, very small line segments (with collision) every few milliseconds. You'll quickly find out if a script-only solution will work.
Personally, I'd create a new scene object that would create your trail and then test for collisions against the line segments. I feel that I would be able to make some optimizations to make sure the test was fast.
12/06/2009 (3:57 pm)
I've seen video of examples where there are hundreds of colliding objects in TGB, so you might be okay if you limit the number of objects that are spawned.For a quick test, you might just create a bouncing ball. Then have the program create random, very small line segments (with collision) every few milliseconds. You'll quickly find out if a script-only solution will work.
Personally, I'd create a new scene object that would create your trail and then test for collisions against the line segments. I feel that I would be able to make some optimizations to make sure the test was fast.
#5
12/07/2009 (2:46 am)
Ok will do thank you for the advice William. I will start testing soon but this coming week at work is going to be murder so I will post my test results asap (probably the weekend)
#6
I always include 1x1-pixel image map in my games, and i can use it in various ways. You can easily stretch that image map over entire screen if you like, or even draw a line with it (set width to some small value, and height to desirable line length)
You can see how i used "line" drawing in this test-project (its unfinished)
www.nutrilans.com/files/Loptice.rar
Try holding and dragging the mouse button.
12/07/2009 (6:21 am)
I draw a line with simple bitmap graphic.I always include 1x1-pixel image map in my games, and i can use it in various ways. You can easily stretch that image map over entire screen if you like, or even draw a line with it (set width to some small value, and height to desirable line length)
You can see how i used "line" drawing in this test-project (its unfinished)
www.nutrilans.com/files/Loptice.rar
Try holding and dragging the mouse button.
#7
12/18/2009 (5:53 pm)
Ok so just to give everyone an update, I ended up just cloning and spawning tiny sceneObjects with collision on them and I just threw that code into the onUpdate(). Tweeked until the sceneobjects were the right size so that nothing could pass through the line. Not sure yet how badly this will affect performance =)
Associate William Lee Sims
Machine Code Games
If you want a scribbled line, I'd probably recommend building a custom scene object unless the number of total length would be limited.
If you just want to change end points, that's just a matter of manipulating the center point of the line, the rotation angle, and the length.
If you want a spline, I'd again recommend a custom scene object.
I can probably give a better answer once I have a better idea of what you are trying to accomplish.