Infinite grid for the Godot game engine

Infinity Grid (InGrid)

An infinite scrolling grid for the Godot game engine (3.x).

A solid component - excellent for things like:

  • 2D procedural universes and worlds
  • Variated parallax scrolling
  • Inifinite runners/jumpers/fallers
  • <insert your fantastic infinite grid abuse here>

Example usage

Features

  • Infinite scrolling!
  • Simple. Only 2 components, simple concept
  • Custom grid cell units (as many bits available as each coordinate in a Vector2 can hold)
  • Lightweight
  • Fairly optimized GDScript code

Important

How Stuff Works™ In order for the grid to be "infinite" the movement model of the grid is like that of a KinematicBody2D. You move the grid relativly to it's current position.

Each cell's xy: Vector2 property combined with some clever position swapping is what allow the grid to continue to scroll to the end of the universe and beyond (given you have enough time on your hands).

When a grid cell leave the viewport, it's position and xy value will be swapped to match the next cell's values in the grid thus allowing for a illusion of infinity if the cell's content changes based on these values.

Install

Simply clone this repository into your project's addons folder.

cd "<path/to/project/root>"
mkdir -p "addons"
cd addons
git clone [email protected]:Larpon/ingrid.git

Usage

Use Grid2D as a base for any grid (you can also derrive from it). Adding multiple grids is supported although performance will depend on various factors such as the cell size of each grid, viewport size etc.

The grid will work out of the box, with sane defaults, but you won't see much unless you do a few things first.

Initialize To initialize the grid with (optional) custom values

func _ready():
    # Optional
    $Grid2D.cell_size = Vector2(256,256)
    $Grid2D.delegate = "res://<path/to/custom/MyCustomCell.tscn>"
    $Grid2D.units = Vector2(1,1)
    $Grid2D.connect("initialized",self,"_on_grid_initialized")

    # Mandatory
    $Grid2D.init()

func _on_grid_initialized():
    $Grid2D.warp(Vector2(0,0))

Move the grid

func _process(delta):
    # Moves the grid one pixel right, relative to it's current position
    $Grid2D.move(Vector2(1,0))

Cell delegates

func _ready():
    ...
    $Grid2D.delegate = "res://<path/to/custom/Cell.tscn>"
    ...

To make the grid seem infinite you'll want to derrive from the supplied Cell type and change the cell Node's contents based on the values of the xy property.

Cell units

func _ready():
    ...
    $Grid2D.units = Vector2(1,1)
    ...

Cell units can be any Vector2 based value set you want. The most common (and default!) value is probably Vector2(1,1). Units are arbitrary and solely used to distinguish each cell from it's neighbours in the grid.

Here's a few examples:

# Every cell.xy increases by 0.5 on each axis on each cell swap
$Grid2D.units = Vector2(0.5,0.5)

# Every cell.xy increases by 10 on each axis on each cell swap
$Grid2D.units = Vector2(10,10)

What units you choose to act on is your choice - and your choice alone

Known issues

There's currently a few known issues you need to consider before deciding to use this.

  • Rigid bodies (RigidBody2D) doesn't work well inside grid cells with the grid's relative movement model. So you must be creative if you want to use RigidBody2D types within grid cells.
  • Grid auto cell filling when resizing is b0rked when more than one row or column need to be added/removed in one call.
  • Only access grid functions from the same thread (Calling from multiple threads will result in wrong coordinates). So don't initialize in _ready while moving in _physics_process. Lock access with a mutex if you try to do so.

Support my work

ko-fi

Webring

Check out my games and other indie dev stuff

Owner
Bearded game developer, artist, musician and V dev. Games: "non - The First Warp", Dead Ascend, Hammer Bees Twitter: @develpon
null
Similar Resources

Scalable Distributed Game Server Engine with Hot Swapping in Golang

Scalable Distributed Game Server Engine with Hot Swapping in Golang

GoWorld Scalable Distributed Game Server Engine with Hot Reload in Golang Features Architecture Introduction Get GoWorld Manage GoWorld Servers Demos

Dec 25, 2022

A pure Go game engine

A pure Go game engine

Oak A pure Go game engine Table of Contents Installation Motivation Features Support Quick Start Implementation and Examples Finished Games Installati

Jan 8, 2023

Terminal-based game engine for Go, built on top of Termbox

Terminal-based game engine for Go, built on top of Termbox

Termloop Termloop is a pure Go game engine for the terminal, built on top of the excellent Termbox. It provides a simple render loop for building game

Dec 29, 2022

A 2D ARPG game engine.

A 2D ARPG game engine.

Abyss Engine is an ARPG game engine in the same vein of the 2000's games, and supports playing games similar to Diablo 2. The engine is written in golang and is cross platform. This engine does not ship with game specific files, and will require a game's assets in order to run.

Dec 24, 2022

A small fantasy game engine in WASM using GoLang

A small fantasy game engine in WASM using GoLang

The GoLang Fantasy Engine (GoLF Engine) is a retro game engine. It draws inspiration from fantasy console projects like pico-8, tic-80, and pyxle. Like those projects it is designed to be a retro-feeling game creation/playing tool. Unlike those projects GoLF is more minimal in scope and only provides an API and a small set of tools to help you create your games. Tools like an image editor and code editor are not built in. Despite this minimalism creating games in GoLF is still easy and should still maintain the retro game feel.

Jul 16, 2022

golang powered game engine

golang powered game engine

Gobatch Go powered engine that offers features from low level opengl abstraction to UI framework. I created this to separate lot of logic from game am

Nov 13, 2022

spx - A 2D Game Engine for learning Go+

spx - A 2D Game Engine for learning Go+

spx - A 2D Game Engine for learning Go+ Tutorials How to run spx tutorials? Download Go+ and build it. See https://github.com/goplus/gop#how-to-build.

Dec 1, 2022

Go Game Engine using SDL for fun

nMage nMage is a (hopefully!) high performance 3D Game Engine written in Go being developed live, with recordings posted on YouTube. This project is b

Nov 30, 2022

HelloSpx - Hello world of Go+ spx game engine

HelloSpx - Hello world of Go+ spx game engine

HelloSpx - Hello world of Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this game

Nov 27, 2021
Arkanoid game in Go using Ebiten game engine with ECS.
Arkanoid game in Go using Ebiten game engine with ECS.

Arkanoid-go Arkanoid game in Go using Ebiten game engine with ECS. You must have Git LFS installed when cloning the repository to download assets. See

Oct 9, 2022
AircraftWar - a game powered by Go+ spx game engine
AircraftWar - a game powered by Go+ spx game engine

AircraftWar - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download thi

Jan 5, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
MazePlay - a game powered by Go+ spx game engine
MazePlay - a game powered by Go+ spx game engine

MazePlay - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this g

Dec 16, 2021
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!

galactic-asteroid-belt Overview A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy! Run To run, you will need Go

Dec 2, 2021
RundQuiz-Game - This is a Go exercise that implements and builds a quiz game from a list of math questions in a CSV file.

Go RundQuiz Game Exercise details This exercise is broken into two parts to help simplify the process of explaining it as well as to make it easier to

Jan 5, 2022
Simple 2D game to teach myself various things about game development and ECS, etc

2d-grass-game I really don't know what to name this game. Its a big grass field, and its in 2d so....2D Grass game This is a simple 2D game to teach m

Jan 17, 2022
Engo is an open-source 2D game engine written in Go.

Engo A cross-platform game engine written in Go following an interpretation of the Entity Component System paradigm. Engo is currently compilable for

Dec 26, 2022
Go 3D Game Engine
Go 3D Game Engine

G3N - Go 3D Game Engine G3N (pronounced "gen") is an OpenGL 3D Game Engine written in Go. It can be used to write cross-platform Go applications that

Jan 9, 2023