Skip to content

Instantly share code, notes, and snippets.

@nisovin
nisovin / file.txt
Last active March 31, 2019 21:27
A description
This is a gist.
extends Node
func _ready():
print("Hello world 2!")
extends Node
func _ready():
print("Wow it works!")
@nisovin
nisovin / LANFinder.gd
Last active March 7, 2021 02:41
Use Godot's UDP multicast feature to find host games on the LAN. Largely untested.
extends Node
class_name LANFinder
const MULTICAST_ADDRESS = "239.10.10.10"
const MULTICAST_PORT = 33221
signal host_found(ip, info)
signal stopped()
var udp := PacketPeerUDP.new()
@nisovin
nisovin / GodotWebFilesExample.gd
Last active May 30, 2022 14:02
Godot Web File Open/Save Dialogs
extends Control
func _ready():
WebFiles.connect("file_opened", self, "_on_file_opened")
func _on_Button_pressed():
WebFiles.open_file(".jpg,.jpeg")
func _on_file_opened(file, content):
$Label.text = file
@nisovin
nisovin / random_point_in_shape.gd
Last active April 17, 2022 19:24
Find a random point in a collision shape
var rng := RandomNumberGenerator.new()
func _ready():
rng.randomize()
# example usage
var shape = $CollisionShape2D
for i in 500:
var sprite = Sprite.new()
sprite.texture = load("res://icon.png")

Godot Threads on Itch.io

UPDATE

As of Feb 2023, itch.io supports SharedArrayBuffer on Firefox, so this document should be unnecessary.

Introduction

Itch.io has recently implemented the ability to use SharedArrayBuffer on its site, which means you can export games with Threads enabled for HTML5. You can learn more about this here. This is great for Godot, as it helps to improve/fix the sound laggyness that sometimes occurs in web builds. It is also now required for Godot 4.

@nisovin
nisovin / Example_WebServer_Usage.gd
Last active April 20, 2022 22:24
GDScript Web Server
extends Node
const HTTP_PORT = 8888
var server
func _ready():
# Create the HTTP server
server = WebServer.new()
@nisovin
nisovin / ScreenMouse.cs
Last active April 29, 2022 21:50
Godot Screen Mouse Position
using Godot;
using System.Runtime.InteropServices;
// This script should be added as a Singleton in Godot
public class ScreenMouse : Godot.Node
{
public Vector2 mouse_position {
get {
return GetCursorPosition();
@nisovin
nisovin / GlobalInput.cs
Created August 18, 2022 05:24
Godot code for getting mouse and keyboard input while window is not focused
using Godot;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class GlobalInput : Godot.Node
{
private Dictionary<int, string> keyWatches = new Dictionary<int, string>();
private Dictionary<int, bool> keyStates = new Dictionary<int, bool>();