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

Random Buttons
How do I randomize a button's position by clicking on a button?

in Engine by (27 points)

we can't see the picture

2 Answers

+1 vote
Best answer
func _on_Randomize_pressed() -> void:
  var index_list = range($"%ButtonContainer".get_child_count())

  for index in index_list.size():
    var button = $"%ButtonContainer".get_child(index_list[index])
    $"%ButtonContainer".move_child(button, index)

random buttons

source code

by (84 points)
selected by
0 votes

You should read Random Number Generation.

First you generate a random number between whatever values you want, and then you use that data to change the position of whatever you want.

Example, lets say you use randf() which returns you a random float between 0.0 and 1.0. You use it twice and then you multiply each number by the width and height of your screen. Finnaly you set the position to those numbers.

by (450 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 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.