官术网_书友最值得收藏!

Initializing

Next, add the _ready() function:

func _ready():
randomize()
screensize = get_viewport().get_visible_rect().size
$Player.screensize = screensize
$Player.hide()

In GDScript, you can use $ to refer to a particular node by name. This allows you to find the size of the screen and assign it to the player's screensize variable. hide() makes the player start out invisible (you'll make them appear when the game actually starts).

In the $ notation, the node name is relative to the node running the script. For example, $Node1/Node2 would refer to a node (Node2) that is the child of Node1, which itself is a child of the currently running script. Godot's autocomplete will suggest node names from the tree as you type. Note that if the node's name contains spaces, you must put quote marks around it, for example, $"My Node".

You must use randomize() if you want your sequence of "random" numbers to be different every time you run the scene. Technically speaking, this selects a random seed for the random number generator.

主站蜘蛛池模板: 栾城县| 衢州市| 阳原县| 涞水县| 南江县| 通化市| 大新县| 抚顺市| 七台河市| 巫山县| 呼图壁县| 祁门县| 赤壁市| 锦屏县| 西安市| 大港区| 冀州市| 曲沃县| 霍州市| 柳林县| 永昌县| 天等县| 池州市| 姜堰市| 延吉市| 永嘉县| 凌海市| 遂平县| 广东省| 五大连池市| 云南省| 嘉善县| 和田市| 东方市| 深泽县| 安乡县| 开鲁县| 广州市| 合作市| 齐齐哈尔市| 勐海县|