0 votes

https://www.youtube.com/watch?v=I7b9APTt6MY
i try this tutorial.but this code not work in 3.1 stable.
i god some advice this thread.
https://godotengine.org/qa/43006/are-you-know-tutorial-of-15-puzzle-sliding-puzzle

I fixed some things but still have problems.
The setpos function results in an error.
This has been replaced by set
position.
Also, set_hidden is an error. What should this replace?
I saw the node2d reference but I do not know.

i copy this code on youtube.
extends Node2D

    var map=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[11,12,13,14]]
    var imgNode = preload("res://levels/0_img.tscn")
    var img=[]
    var move =Vector2(0,0);var speed=4

    func _ready():
        for n in range(16):
            img.append(imgNode.instance())
            img[n].set_frame(n)
            add_child(img[n])
            for y in range(4):
                if map[y].find(n) != -1:
                    img[n].set_pos(Vector2(map[y].find(n)*100, y*100))
        img[15].set_hidden(true)
        set_physics_process(true)

    func step(key,dir):
        if Input.is_key_pressed(key) and move == Vector2(0,0) or move == dir:
                for y in range(4):
                    if map[y].find(15) != -1:
                        var pos = Vector2(y,map[y].find(15)) +dir
                        pos.x = min(max(pos.x,0),3);pos.y = min(max(pos.y,0),3)
                        img[map[y][map[y].find(15)]].set_pos(Vector2(pos.y * 100,pos.x * 100))
                        if img[map[pos.x][pos.y]].get_pos() != Vector2(map[y].find(15)*100,y*100):
                            move = dir
                            img[map[pos.x][pos.y]].set_position(img[map[pos.x][pos.y]].get_pos() - Vector2(dir.y * speed,dir.x * speed))
                        else : map[y][map[y].find(15)] = map[pos.x][pos.y];map[pos.x][pos.y] = 15;move = Vector2(0,0)
                        break
    func fixed_process(delta):
        step(KEY_DOWN,Vector2(-1,0));
        step(KEY_RIGHT,Vector2(0,-1));
        step(KEY_LEFT,Vector2(0,1));
        step(KEY_UP,Vector2(1,0));
in Engine by (182 points)

1 Answer

0 votes

node.set_visible(value) or node.visible = value

by (9,615 points)

thanks,there are no more error

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.
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 webmaster@godotengine.org with your username.

Categories