Skip to content

gdzig/gdzig

Repository files navigation

gdzig

Idiomatic Zig bindings for Godot 4.

DISCLAIMER

This library is currently undergoing rapid development and refactoring as we figure out the best API to expose. Bugs and missing features are expected until a stable version is released. Issue reports, feature requests, and pull requests are all very welcome.

Prerequisites

  1. zig 0.15.1
  2. godot 4.4

Usage:

See the example folder for reference.

Code Sample:

pub fn _enterTree(self: *Self) void {
if (Engine.isEditorHint()) return;
var normal_btn = Button.init();
self.base.addChild(.upcast(normal_btn), .{});
normal_btn.setPosition(Vector2.initXY(100, 20), .{});
normal_btn.setSize(Vector2.initXY(100, 50), .{});
normal_btn.setText(.fromLatin1("Press Me"));
var toggle_btn = CheckBox.init();
self.base.addChild(.upcast(toggle_btn), .{});
toggle_btn.setPosition(.initXY(320, 20), .{});
toggle_btn.setSize(.initXY(100, 50), .{});
toggle_btn.setText(.fromLatin1("Toggle Me"));
godot.connect(toggle_btn, "toggled", self, "onToggled");
godot.connect(normal_btn, "pressed", self, "onPressed");
const res_name = String.fromLatin1("res://textures/logo.png");
const texture = ResourceLoader.load(res_name, .{}).?;
defer _ = texture.unreference();
self.sprite = Sprite2D.init();
self.sprite.setTexture(Texture2D.downcast(texture) catch unreachable);
self.sprite.setPosition(.initXY(400, 300));
self.sprite.setScale(.initXY(0.6, 0.6));
self.base.addChild(.upcast(self.sprite), .{});
}

Community

Find us in the gdzig Discord server.

About

Zig bindings for Godot 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages