0 votes

Here is my code for map generation. I want to make particles emit from
Dirtwall to produce a smoke-like effect from them. I'm considerably
far in my game development, but the further I get, the more confused I
am(guess thats learning, though.) How would i do this? I have a
particle scene ready to call but even then I don't know how i would
specifically set EACH particle on each Dirtwall generated.

 func make_map():
    loadingbar.update_percent(load_percent)
    #core of map floor / rock
    for x in range(1, current_map_size.x - 1):
            for y in range(1, current_map_size.y -1):
                    var num = rand_range(0.0, 100.0)
                    if num < percentage_floors:
                        set_cell(x,y, TILES.Wispfloor)
                        update_bitmask_region(Vector2(0.0, 0.0), Vector2(current_map_size.x, current_map_size.y))
                    else:
                        set_cell(x,y, TILES.Dirtwall)
    #Rockborder set  L/R Sides
    for x in [0, current_map_size.x - 1]:
        for y in current_map_size.y:
            set_cell(x, y, TILES.Dirtwall)
            #Top n Bot Sides
    for x in current_map_size.x:
        for y in [0, current_map_size.y - 1]:
            set_cell(x, y, TILES.Dirtwall)
func smooth_map():
    load_percent += 10
    loadingbar.update_percent(load_percent)
    #
    for x in range(1, current_map_size.x - 1):
        for y in range(1, current_map_size.y - 1):
                var number_of_neighbor_walls = 0
                for direction in neighbor_dir:
                    var current_tile = Vector2(x,y) + direction
                    if get_cell(current_tile.x, current_tile.y) == TILES.Dirtwall:
                        number_of_neighbor_walls += 1
                #check if we should change tile based on neighboring tiles
                if number_of_neighbor_walls > 4:
                    set_cell(x,y, TILES.Dirtwall)
                elif number_of_neighbor_walls < 4:
                    set_cell(x,y, TILES.Wispfloor)
                    update_bitmask_region(Vector2(0.0, 0.0), Vector2(current_map_size.x, current_map_size.y))
asked Jun 18 in Engine by moyles (16 points)

From your code it's not apparent when and where you want to spawn the particles. In principle this is as easy as setting the global_position-property of the Particle2D to the global_position of the tile which you can get by the following line:

to_global($TileMap.map_to_world(Vector2(x, y)))

Edit: map_to_world expects a Vector2() instead of two variables for x and y

I haven't included any code that has to do about the particle generation, but that makes sense. would that apply the particles to each and every specific Dirtwall generated block?
Thats what i'm trying to pull off

1 Answer

0 votes

would that apply the particles to each and every specific Dirtwall generated block?

You mean to all of them at the same time? No. The line I posted above will give you the global coordinates of the TileMap-cell (x, y) - and then you could spawn a particle effect there. If you want to do this for all tiles you would do something like:

for cell in $TileMap.get_used_cells():
    var particle_position = to_global($TileMap.map_to_world(cell))
    var new_particle = load("<PathToParticleScene>").instance()
    new_particle.global_position = particle_position
    add_child(new_particle)

And if you'd only want it to do for all tiles with a certain tile-id (let's say 2):

for cell in $TileMap.get_used_cells_by_id(2):
    var particle_position = to_global($TileMap.map_to_world(cell))
    var new_particle = load("<PathToParticleScene>").instance()
    new_particle.global_position = particle_position
    add_child(new_particle)
answered Jun 20 by njamster (8,990 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.