how to get screen width and height in godot

To get the screen width and height in Godot using the Go language, follow these steps:

  1. Import the necessary packages:
import (
    "github.com/godot-go/godot-go/pkg/gdnative"
    "github.com/godot-go/godot-go/pkg/gdnative/core"
)
  1. Define a class that will inherit from gdnative.Node:
type MyNode struct {
    gdnative.NodeImpl
}
  1. Implement the _Ready function to get the screen width and height:
func (n *MyNode) _Ready() {
    screenSize := core.GDViewportGetVisibleRect(core.GDViewportGetMain())
    screenWidth := screenSize.Size().Width
    screenHeight := screenSize.Size().Height

    // Use the screen width and height as needed
    // ...
}
  1. Register the MyNode class with Godot:
func init() {
    gdnative.RegisterInitCallback(registerClasses)
}

func registerClasses() {
    gdnative.RegisterClass(&MyNode{})
}
  1. Compile the Go code into a Godot module. Refer to the Godot documentation for instructions on how to compile Go modules.

  2. In your Godot project, create a new scene and add an instance of your MyNode class to the scene.

  3. Run the project, and the _Ready function will be called, retrieving the screen width and height.

These steps will allow you to get the screen width and height in Godot using the Go language.