Some concepts and components commonly used by godot (organized in the official tutorial)

  1. Others' godot qa is great: Godot Practice Q&A | indienova Independent Games

  2. Adjust the resolution of the game project, project settings, display, windows, set width&height

  3. Also, scroll to the bottom of the subsection, and in the "Stretch" options, set Mode to "2d" and Aspect to "keep". This ensures that the game can be scaled consistently on screens of different sizes.

  4. To detect the collision of A and B, use Area2D, and its child objects must have CollisionShape2D

  5. Sprite animation: AnimatedSprite -> SpriteFrames  A sprite animation can contain a variety of actions, and each action will contain a series of animations

  6. Add collision: CollisionShape2D

  7. In the script, use var xx = 123 for ordinary variable declarations. If you need to export variables, use export var xxx = 123. You can also export special types of variables, export(PackedScene) var mob_scene

  8. When the node enters the scene, _ready will be called, which can be understood as the node's constructor

  9. The _process function is called every frame. The delta parameter of the _process() function is the frame length - the time it takes to complete the previous frame. Using this value, you can ensure that your movement will not be affected by frame rate changes , note that if you need to set physics-related attributes, you need to set them in _physics_process

  10. Project -> Project Settings -> Key Mapping, where you can use strings to map the operations of certain keys

  11. Use Input.is_action_pressed() to detect whether the key is pressed, and return true if pressed, otherwise return false.

  12. Commonly used properties of objects: velocity (Vector2 object)

  13. To manipulate child objects, use $xxxx, where $ is shorthand for get_node(). So in the code above, $AnimatedSprite.play() is the same as get_node("AnimatedSprite").play(). $ Returns the node at the path relative to the current node, or null if the node cannot be found. Since AnimatedSprite is a child of the current node, we can use $AnimatedSprite

  14. vector2 can use velocity.normalized() for vector unitization

  15. Clamp position: clamp, clamp A value means to clamp it to the given range. eg: position.x = clamp(position.x, 0, screen_size.x)

  16. Objects of type AnimatedSprite can call the play & stop function

  17. $AnimatedSprite.animation = "walk" can choose animation $AnimatedSprite.flip_v = false can flip vertically $AnimatedSprite.flip_h = velocity.x < 0 can flip horizontally

  18. $AnimatedSprite.frames.get_animation_names(), get all animation names in animateSprite

  19. $AnimatedSprite.animation = mob_types[randi() % mob_types.size()] animates

  20. If you want the generated "random numbers" to be different each time you run the scenario, you must use randomize(). We will use randomize() in the Main scene

  21. You can use rand_range(a,b) to generate numbers between a and b

  22. add_child(), for dynamically adding items to the current instance

  23. VisibilityNotifier2D, signal: screen_exited, will trigger when the object leaves the screen

  24. Modify the font: Label->themeOverrides->fonts->font->new DynamicFont

  25. The hide() function can hide the current instance

  26. signal correlation

    1. Define the signal: signal hit, indicating that a certain object will trigger a signal to the outside world

    2. Trigger signal: emit_signal("hit")

    3. The signal can also optionally declare one or more parameters, signal hitb(old,new)

    4. Safely modify the property: $CollisionShape2D.set_deferred("disabled", true), if the collision shape of the disabled area during the engine's collision processing may cause errors. Use set_deferred() to tell Godot to wait until it is safe to disable the shape before doing so.

    5. More signal information Using signals — Godot Engine (latest) Simplified Chinese documentation

	# 动态链接信号
	# 方法1.手动指定
	#get_node("../../golden/Area2D").connect("golden_touch", self, "_on_Area2D_golden_touch")
	#get_node("../../golden/Area2D2").connect("golden_touch", self, "_on_Area2D_golden_touch")
	
	# 方法2.动态遍历
	var goldens = get_node("../../golden").get_children()
	for gold_obj in goldens:
		gold_obj.connect("golden_touch", self, "_on_Area2D_golden_touch")
		gold_obj.connect("area_enter", gold_obj, "_on_Area2D_area_entered")

Guess you like

Origin blog.csdn.net/dyyzlzc/article/details/125706308