How do I draw lines with physic behavior?

Get help using Construct 2

Post » Thu Dec 27, 2012 4:15 pm

Hi,

I was wondering if it would be possible to reproduce the gameplay of drawing physics games.

For example:

Crayon Physics Deluxe
http://www.youtube.com/watch?v=avkacGQKWecJailson2012-12-27 16:15:55
B
228
S
6
G
8
Posts: 86
Reputation: 12,295

Post » Thu Dec 27, 2012 5:01 pm

The main challenge that I am seeing is how you would allow the user to create a sprite shape and then the computer will dynamically know the boundary of that shape. I know you can create any shape you want and change the bounding box to fit that shape. But that customization of the bounding box is done by the designer of the game. I'm not sure if it's possible to give the user the ability to do that on the fly.

But to answer your initial question of how to draw lines with physics behavior, it sounds like you are asking two different questions. If the question was just how do you add physic characteristics to a line, than that's easy as you would just draw a sprite that looks like a line and give it the behavior or physics. But you're probably asking more about the drawing part meaning how does a user dynamically create a sprite with a fitted bounding box and that's of course the hard part.

So to answer your question, I don't know. But I'd be interested if it can be done.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Thu Dec 27, 2012 6:48 pm

alight, here is a commentary, and a solution for you too look deeper for a better solution if possible.

When manually writing game code for BOX2D and other physics engines. The programmer has the ability to set vector points for the collision shape. I don't know if C2 allows for setting collision shapes during run time. However you might be able find a plugin. If not you can try to use the answer below.


10px lines.
As you have your mouse(or touch) start drawing. draw graphical lines with no physics. These lines are done in 10px spurts burts by startx/y when first touching and when the mouse move a distance of 11px away lock the fgx line in start a new 10px line. keep this up until the player released or some other limit is met.

when then player released the mouse, iterate through each of the 10px lines and create a new line which is a PhysicsLine and joint each pLine to the previous. Now you have a physics shape.

you might be able to get away with more than 10px. Experiment as you would like.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Thu Jan 17, 2013 12:56 am

guys! thanks for answering and sorry for delaying on feedback due to vacations!

well...

@farmerdwight : you are right, I know how to handle with physics on C2, my question is more about drawing lines and then turn then physic objects.

@jayderyu: you approach seems very reasonable. I tried before something like this but I didnt use a 10px threshold. I will give a shot on this suggestion and then I report my results.

Thanks again!
B
228
S
6
G
8
Posts: 86
Reputation: 12,295

Post » Thu Jan 17, 2013 1:32 am

It's very possible, there another HTML5 version of this game.

http://scotland.proximity.on.ca/asalga/crayonphysics/

I doubt if it can be done by loop, i couldn't help you.


Anyways, there a quick and dirty trick to create static physic objects according to this
http://www.scirra.com/forum/plugin-unistroke-gesture-recognizer_topic48720.html
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Thu Jan 17, 2013 1:54 am

@Joannesalfa Nice example!

Unitroke plugin also may give some lead... maybe the way would be create a plugin for that... (of course I am procrastinating it, but may be the time to show that I am a man not a rat).

Thanks!
B
228
S
6
G
8
Posts: 86
Reputation: 12,295


Return to How do I....?

Who is online

Users browsing this forum: makkancs and 26 guests