How to draw a line using mouse, then have object follow it?

chongyunxiang

  • Posts: 216
Hi, not sure if this has been done on Stencyl before, but how do I hold down left button mouse and move the mouse to draw a line, when finished, release the mouse and the actor will follow the line?

Thanks!

JeffreyDriver

  • *
  • Posts: 2152
I'm not entirely sure how you would achieve this, but I believe that the basic idea would use lists. When the mouse is down you create a list of the coordinates the mouse moves through, and on release you get the actor to move through the same list of coordinates.

I'd be interested in seeing the code when you get it working.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

CmdrWhitey13

  • Posts: 503
Check out my PENCYL PERFECT wip project.

http://community.stencyl.com/index.php/topic,47246.0.html

This is drawing a line that the ball is rolling on.

As Jeff said, lists are your friend.

@Theindiestation i believe has done a tutorial on waypoints.  Might be how you want to move the actor.

chongyunxiang

  • Posts: 216
I'm watching theindiestation's video about Lists. Are you referring to his Distance between 2 actor video? And CmdrWhitey13, could you share with us the code that runs your drawing mechanics?

CmdrWhitey13

  • Posts: 503
Are you referring to his Distance between 2 actor video?

That be it.

As for drawing, it's more like placing images.

Thresh

  • Posts: 19
This is drawing a line that the ball is rolling on.

Is it possible to make it so the ball can move and jump on command, instead of rolling? Cheers.

CmdrWhitey13

  • Posts: 503
This is drawing a line that the ball is rolling on.

Is it possible to make it so the ball can move and jump on command, instead of rolling? Cheers.

If it is set up to function, it is possible. The ball is affected by gravity, hence the rolling.  Anything is possible. Creativity is key.

Fool

  • Posts: 88
Hi, this isn't too difficult to solve.

The key thing is to save the two points that you want to move between, and use that to calculate distance along the x axis and y axis. Then when you move your ball, you set the x an y axis to 'd / distance', or some fraction of the distance based on the formula in the attachments.

As an example I have some code, not entirely complete, but it should set you heading in the right direction.

Pay attention to what I circled in yellow, those are the important bits. Good luck.

Note: x0 and y0 are the position of your ball. x1 and y1 are the position that you want the ball to move to.