What function do I need to display a sprite at an array position?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bgegg

I use self.add_child () and want to order the textures as horizontal.
extends Node2D

var sprite = load("res://0_practice/array/sprite.tscn")
var sprite_ins = sprite.instance()

var simple_array = [1,1,1,1]

func _ready():
	for i in range(4):

Is it possible to arrange four textures as horizontal?
insert function seem difference

That’s the docs from 2.1
Here’s the 3.1 version: Array — Godot Engine (3.1) documentation in English

Dlean Jeans | 2019-07-04 12:10

How do you add_child a sprite?
The texture is 64px

for i in range(4):
	simple_array.insert(i,sprite_ins)
	add_child(sprite_ins[i])

bgegg | 2019-07-04 20:30

I’m unclear what you’re trying to do in your question.

sprite_ins is a Sprite not an Array so you can’t add [i] after it.
simple_array is an array of int so I dunno why you insert the same sprite_ins (which is a Sprite) 4 times.

Dlean Jeans | 2019-07-05 07:19

sorry,my english is difficult to understand
i want order sprite like this by array

array = [1,1,1,1] is sprite position.
enter image description here
This is useful when making puzzles

bgegg | 2019-07-05 08:04

array = [1,1,1,1] is sprite position.

How does that work?
Positions in 2D are stored as Vector2.
1 is the position? Horizontally? Vertically?

Dlean Jeans | 2019-07-05 17:28

thanks for comment.
it is horizontaly position.
I want to fill a square with a two-dimensional array like a puzzle

bgegg | 2019-07-05 20:13

i finished this problem.
thank.

extends Node2D

var sprite = load("res://0_practice/simple/sprite.tscn")



func _ready():
	main()
	
func main():
	var array = []
	for i in range(4):
		array.append(null)
		print(array)

		var piece = sprite.instance()
		add_child(piece)
		piece.position = sprite_position(i)

func sprite_position(x_loop):
	var x_pos = 0 + 64 * x_loop
	return Vector2(x_pos,0)

bgegg | 2019-07-06 01:30