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

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.

主站蜘蛛池模板: 巴青县| 宁强县| 台湾省| 锡林郭勒盟| 镇平县| 柳河县| 梓潼县| 灵璧县| 玉屏| 黔江区| 陈巴尔虎旗| 吐鲁番市| 漳浦县| 南澳县| 新化县| 瓮安县| 桐庐县| 宁乡县| 定结县| 灌南县| 怀集县| 黔西县| 华宁县| 无锡市| 绍兴县| 秦皇岛市| 方山县| 盖州市| 绍兴市| 永顺县| 象山县| 新竹市| 普安县| 灵璧县| 汾阳市| 双桥区| 临澧县| 射阳县| 克拉玛依市| 阳城县| 黄梅县|