This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

There is only mouse clicking on objects in this game so it doesn't need the physics engine. When creating instances of the 2D Node, what is the easiest way to create them with one of nine images (and set some variables)?

There is no need to interchange these images midgame.

Godot version 3.3.4
in Engine by (54 points)

1 Answer

+1 vote
Best answer

Node2d with an image is a Sprite node. If You really don't want to add any script to your sprites You can use Autoload singleton ( or any menaging node in the scene tree ). Your manager node will have variable of type area containing all possible images. It will also have a method called on mouse click to pick one of those images according to chosen algortihm ( or randomly ) and instance new sprite, set its texture as chosen image, set sprite metadata as your chosen variables, and finally add child of complete Sprite.

by (8,188 points)
selected by

Some typo like area rather than array as you mean. I intend to have Sprite nodes instanced on starting because there 900 of them and they will have probably need to have script. It is a normal integer variable needed to set for each of them. The Sprites nodes will be mouse clickable.

You don't need to instance all 900 sprites. Preload all of your 900 images instead, it will be faster. Then on mouse click there will be only one Sprite instanced and childed at a time, and one of those images will be chosen for it. Images are of type Resource and you only need to preload them once, no need to instance, multiple sprites can use the same preloaded image. And as I said, if You only want sprites to keep one integer value, You also don't need script for them, instead use setmetadata() and getmetadata()

There are not 900 images, only 9 are stated. There will be script to use the integer value- its a Sudoku. As always GODOT jargon trips me up.

I see :). If so You can think of a TIleMap instead of Sprites. TileMap has useful methods, that will make counting total values in row and column much easier. It is always symmetrical, You won't have to count positions for sprites to be adjacent to each other. Tilemap has methods to keep images and set them to your sprites easily. You can also use another tilemap on top of the main one to hide tiles from the player.

Buttons seems to have the all the functionality that I need.

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.