Draw a path after a physics object

  • Hello.

    I got a question I was researching for some time today. Is there any "right" way to draw a line that represents a physics object path. For example a sphere is falling down is some kind of labyrinth and I need to draw a path that a sphere took. Currently I'm spawning a dot at the sphere position every "0.n" seconds but this is not working as needed because the sphere can change it's speed and the dots representing the path will be more dense when it's slow. The perfect way would be to draw a path every "n" pixels traveled, but I can't find a way to get the position of the last spawned point to calculate the distance.

    Any ideas?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maybe the example I linked to inThis topic could be of use..

  • Easiest thing would be using the canvas plugin with "line to" and draw path.

    If you wanna draw every x traveled use something like (posx, posy = global vars, set them to sprite.x and sprite.y at the start of the layout):

    distance(sprite.x,sprite.y,posx,posy) greater of equal 10: call function "draw line"

    set posx = sprite.x

    set posy = sprite.y

    and function draw line contains the drawing on the canvas.

    This would prevent you from having to deal with a big number of objects.

    If you playing area is very big ofc it is better to just spawn those points and then delete them when offscreen or use multiple canvases.

  • Thanks for the fast reply <img src="smileys/smiley2.gif" border="0" align="middle" />

    I actually combined both of your suggestions to get the result I was looking for.

    Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)