0 votes

I.e. when the e in "real" it's clicked, a and l also have to return to the letterbox along with e letter.
Code:

func _ready():
    $AnimationPlayer.play("intro")
    randomize()
    for i in range(4):
        for j in range(4):
            var tile:LetterTile = Letter.instance()
            $LetterBox.add_child(tile)
            # warning-ignore:return_value_discarded
            tile.connect("tile_clicked", self, "on_tile_clicked", [tile])
            tile.position = Vector2(i * TILESIZE, j * TILESIZE)
            tile.box_position = tile.position
    initialize_dictionary()

func on_tile_clicked(tile:LetterTile):
    var start_pos = tile.global_position
    if tile.get_parent().name == "LetterBox":
        if word_node_erased == true:
            add_child(word_node)
            word_node_erased = false
        $LetterBox.remove_child(tile)
        $Word.add_child(tile)
        tile.global_position = start_pos
        current_word += tile.letter_value
    else:
        #This part i mean.
        var tile_position = tile.get_position_in_parent()
        $Word.remove_child(tile)
        $LetterBox.add_child(tile)
        $Tween.interpolate_property(tile,"position", start_pos - $LetterBox.position, tile.box_position,0.2,Tween.TRANS_LINEAR)
        current_word = current_word.substr(0, tile_position) + current_word.substr(tile_position + 1, current_word.length())

enter image description here

in Engine by (122 points)

1 Answer

0 votes
Best answer

I changed the code in my original Github repository. Here's what you would need to change in your code:

https://github.com/t-karcher/Bookworm_Adventures/commit/254cc43324cde17a2a5316d8268f768d2f3bd35b

I basically moved the removal code in an own function, which is called not only for the clicked letter, but for all following letters as well.

by (1,758 points)
selected by
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.