Game Development Community

Creating Objects along a line?

by Jeremy Dull · in iTorque 2D · 10/14/2011 (12:08 am) · 4 replies

I am pretty new to the Torque 2D world and have done most work in the TGE. I am pretty good at under standing the scripting, but I am at a bit of a lose here and looking for some direction.

I am trying to make code to insert a series of objects based on the users finger movement. Pretty much allow the user to draw a line with their finger and then have some static objects appear where they drew the line.

A point A to point B style would work, but I am really trying to make it where the user could draw a curved line and something like a wall would fill itself in along that line.

I have worked through all the tutorials for iTorque and I even own the platformer kit, but I am not quite sure how I would have it spawn the objects along the line and auto rotate and adjust the static sprites so they would spawn and curve along the line drawn.

If anyone could help point in the right direction or show me a resource that I could use that would get me started I would greatly appreciate it.

About the author

Founder and CEO of Blackstaff Studios. Our focus is to make fun and simple games and software for the everyday person. Currently working on a project for the iOS platform using iTorque 2D


#1
10/14/2011 (12:20 pm)
@Jeremy - There are two approaches I would take for part 1 (drawing a line)

1. Take the path creator/renderer the editor uses and modify it to work in a game, manipulated by a touch.

2. Create a new function that uses custom rendering code to draw the line. There are lots of free examples of this kind of code out there, specific to iOS drawing.

The next part (placing sprites along a line) depends on what solution you use for the drawing. You will want to have some kind of "stepping" system, which you will use for placing objects at intervals.
#2
10/19/2011 (11:15 am)
@Michael - Thanks for the input I really appreciate the point in the right direction.

I have just gotten the code to work with straight lines so I have the basic idea at this point, on what I need to do. I will look into the iOS drawing examples that you mentioned since it seems like that is what I will need to base my idea of giving the user the ability to make a curved walled to reflect my objects off.

Also I appreciate your mantra that I came across in one of your threads.... "Read, Read Code, Code." It is helped me out a lot since I was diving into the Code part way to soon from the get go and it pretty much caused a headache and a half.

Thanks again.
#3
10/30/2011 (3:00 am)
I hate to act the noob, but I have been searching for days, and the only hit I get on drawing lines via torque in iOS that has any relevance is this thread.

Michael - could you give me a stronger push in the right direction....
Jeremy - could you share your solution... It seems crazy to me that this is so hard to find considering this would be a very popular thing to do.

Thanks,
Travis

P.S. I would think a straight line, curved line drawing tutorial would be a great addition to the official docs.
#4
10/30/2011 (7:40 am)
@ Travis. What I would do, in its simplest form, would be to have a sprite. This sprite (lineBase) is the smallest unit of the line you can afford, so say, just for argument it is 1 unit x 1 unit in size. When the user uses drag (or move), in the game.cs, on the onTouchesMove(), record the pos, and place a sprite there. Thats it, It will continue to place sprites, where ever your finger is, until onTouchesUp.