[Solved] Drawpathfinding to create a road

Hi i really new to Gdevelop, and trying few thing before starting a real project.
My goal is
-Something is delete
-create an Object
-Path to a point
-Put a texture/object on that path
That part is my problem, i can’t manage to find a way to use the path create by a “Shape painter” using “Drawpathfinding” extension, to create a road texture on it.

The same path will be use multiple time by multiple object, and i would like to apply a road texture on it.

i’m not sure this is clear, and i hope someone will be able to help me.


Hello Touiix. There might be a better method but this is one method.

Here is a simple road with a road texture. This is basic looking. For something more realistic, you might want to draw an edge or use procedural generation to mix premade tiles. That’s more advanced. I have little experience with that and that’s probably down the road. Today, let’s do something relatively simple.

Here’s my test project. (Click the green [code] and [download zip] unzip and open the JSON file.

Try me: click anywhere to move.

Let’s walk through it. The pathfinder behavior stores the path in nodes. You get the positions in various ways. I’m used the GetNodeX(node number) and GetNodeY(node number). The node number starts at zero.

This uses 1 number scene variable named counter.

It uses 3 objects. A player sprite with the pathfinder behavior. I turned the rotate the player off and I reduced the virtual grid width and height to 10. Ten is a good number. The smaller the number the closer the grid points. It adds a finer movement but also takes a little more time to calculate.

A shaper painter. I set the shape painter colors to white and unchecked both boxes.

A tiled sprite that I drew a simple road texture on. I stretched the tiled sprite to fit the scene, it doesn’t matter where the shape painter is placed. The player should be the top most object.

I added the extension Object Masking. This uses a sprite or shape painter as a mask. The brighter the color of the mask image the more is shown of the other object. White shows the masked image, darker colors reduce the opacity.

Here are the events.

At the beginning, it sets up the mask.
When the mouse is released, it moves the player.
The repeat event is set to the number of nodes minus 1 because it draws a line from the counter node to counter node +1.
Next, draw a line from node to node.
I added a circle at each node to make the line a continuous shape otherwise it has breaks.
I added 1 final circle to add a curve at the last node.

With the circle versus without
image image

If the map is large and there’s going to be a lot of roads then you probably want to add a new shape painter instance and a tiled sprite instance each time. Or maybe a different strategy. A large image wouldn’t cull when off screen like smaller or separate images. This should definitely get you a starting point.

Thanks a lot, you give me a lot a useful information i will start from here.
In the end i would like it to work in an almost Infinite Map, but with a limited number ou pathing (4-5 max) it should make the job.

Again thanks a lot for all the information gonna try this out tomorrow.

1 Like

Work perfectly thanks a lot !

1 Like