Summary of some problems encountered in getting started with Godot

Dynamically add scenes

1.func _ready():  
2.    for i in range(50):  
3.        addIconsButton()  
4.  
5.  
6.func addIconsButton():  
7.    #添加自定义图标按钮  
8.    var icon = preload("res://IconsButton.tscn").instance()  
9.    self.add_child(icon)  

UDP accept message

1.var peer  
2.  
3.  
4.func _ready():  
5.    peer = PacketPeerUDP.new()  
6.    peer.listen(9999)  
7.  
8.  
9.  
10.func _process(delta):  
11.    if peer.get_available_packet_count() > 0:  
12.        var data = peer.get_packet().get_string_from_ascii()  
13.        print(data)#从对象获取数据  
14.        print(peer.get_packet_ip())#获取IP地址  
15.          
16.        var lab = Label.new()  
17.        lab.set_text(data)  
18.        self.get_child(0).add_child(lab)  

Make the sub-controls in the GridContainer adaptive to the position

You need to check Expand in the SizeFlags of the child control, and also check this item in the GridContainer control itself

The computer side is vertical, but the mobile phone is horizontal so that the screen of the mobile phone is consistent with the computer

 There will be a few more bytes when sending data packets over the Internet

 

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.bind(("", 9999))
sock.sendto("你好".encode(), ("255.255.255.255", 9999))
while True:
    recv_data = sock.recvfrom(1024)
    text = recv_data[0].decode(encoding='UTF-8')
    text = text[8:-1]
    print(text)
    if text == "getData":
        print("准备发送数据:")
        sock.sendto("你好".encode(), ("255.255.255.255", 9999))

 

You can see text[8:-1]

This is because the put_var function is used in godot to send. If the put_var() function is used, 4 bytes will be added in front, because put_var() is dedicated to the online connection of godot programs, and variable type judgment data will be added in front .

You can use put_packet()

 

 Android phone cannot connect to the Internet

var err = peer.set_dest_address("192.168.31.70",19999)#Set sending address port

see the error is

● ERR_CANT_CREATE = 20

Could not create error.

Check the official github, it is a permission issue. The solution is to check the permissions when packaging

method one:

Method Two:

If you don't want to check all of them, you can only check Internet network permissions

 The mobile phone cannot install the packaged APK

Prompt that there is no certificate, you can re-sign the apk with the 360 ​​signature tool

 

 Control detects mouse click events

Reference: InputEventMouseButton — Godot Engine (stable) Simplified Chinese documentation

Dynamically modify the color of the Panel panel at runtime

 

  1. Add a StyleBoxFlat to the ThemeOverrides column of the Panel control so that you can manually set the color

 

  1. The core step is line 23, which gets the properties of the current control
  2. This property name can be obtained by hovering the property bar with the mouse, for example

 

 

  1. Of course, in addition to the get function, you can also use the set function, and some attributes can be obtained in this way
  2. How to dynamically set Custom Styles in the code [godot bar]_Baidu Post Bar (baidu.com)

Add a custom attribute column

Is there a way to create truly custom types in Godot? - I love learning network (5axxw.com)

(65 messages) [Godot] Example of a dynamic attribute list_Apprentice Zhang's Blog-CSDN Blog

the first method:

export var a = 1

You can also specify the type export var a:String

You can see the documentation to view the export usage

The second method:

  1. First, you need to add the tool keyword at the top

 Then you need to override this built-in function _get_property_list

  1. final effect

 The relationship between controls and script files is too messy and the directory is not easy to organize

When creating a new script, you can choose a built-in script

In this way, the control scene and the script are the same file, which is convenient for organizing the directory

bind send signal

  1. New signal signal drag
  2. Send signal self.emit_signal("drag")
  3. self. can not be added, if the signal needs to be emitted by reference in other scripts, such as a.emit_signal("drag")
  4. Binding signal gridlayout.connect("drag", self,"_on_IconsGridLayout_draw")
  5. Note that the gridlayout before connect indicates the instance where the signal is located, and self indicates the instance where the callback function is located
  6. If you need to take parameters as follows
  7. signal drag(relative)#New signal with parameters
  8. self.emit_signal("drag", event.relative)#Emit a signal with parameters
  9. The corresponding callback function with parameters: func _on_IconsGridLayout_draw(relative):
  10. In addition, define signals in other classes as follows
  11. node_ins.add_user_signal("custom_user_signal")

The input callback function of the parent control will be affected by the child control.
If the child control is clicked, the parent control cannot receive the signal? Is there a way to directly make child controls immune to click events?

 

 

Guess you like

Origin blog.csdn.net/u012863565/article/details/125018469
Recommended