Structure of a Sprite

Enter the Gungeon uses Toolkit 2D for rendering most of the things you see in game, with some exceptions such as UI. TK2D is a very friendly Unity plugin for game developers, however unfortunately it's significantly less friendly without access to the Unity editor. As a result, a lot of helper classes, structs and methods exist in Semi to aid in handling sprites.

A TK2D sprite is a subclass of tk2dBaseSprite . That's not all there is to it, though. You don't just load a single texture and assign it to a sprite - not only are there multiple kinds of sprites depending on the use case, sprites also operate based on sprite collections. A sprite definition is an object of type tk2dSpriteDefinition, while a sprite collection is an object of type tk2dSpriteCollectionData. Note that there also exists a type called tk2dSpriteCollection, which is not a sprite collection, and instead some internal thing that's irrelevant for modding the game.

Sprite collections hold a list of sprite definitions. Each definition specifies a texture, a name and data that determines what that sprite definition actually holds. The UV fields tell Unity how to map a texture to a rectangle on the screen, and position fields tell it how to actually display that rectangle. Through the use of UV mapping, you can create a sprite definition that holds a region of the actual texture assigned to it, which is how the game loads almost all sprites - using huge sprite atlases. The types used here are the standard types provided by Unity - Texture, Vector3, etc.

It is also worth mentioning that Unity does not have a true 2D (pixel-based) engine. 2D Unity games usually just render objects on a plane facing the camera at a 90 degree angle. Gungeon does this a bit differently, as it renders walls as actual 3D objects and normal sprites at a 45 degree angle, but this shouldn't mean much for you other than the fact that you'll see 3D types like Vector3popping up in 2D code all the time.

Luckily, you don't have to care about almost any of this yourself, because not only does Semi contain a bunch of structures that make it easier to manipulate sprites through just code alone and a lower-level API for constructing them, it even has the ability to load specially formatted files to do all the work for you. You can check out how they look later in this section.

Last updated