tModLoader v0.11.8.9
A mod to make and play Terraria mods
BackgroundTextureLoader.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4namespace Terraria.ModLoader
5{
6 //todo: further documentation
10 public static class BackgroundTextureLoader
11 {
12 public const int vanillaBackgroundTextureCount = Main.maxBackgrounds;
14 internal static IDictionary<string, int> backgrounds = new Dictionary<string, int>();
15
16 internal static int ReserveBackgroundSlot() {
17 int reserve = nextBackground;
19 return reserve;
20 }
21
25 public static int GetBackgroundSlot(string texture) => backgrounds.TryGetValue(texture, out int slot) ? slot : -1;
26
27 internal static void ResizeAndFillArrays() {
28 Array.Resize(ref Main.backgroundTexture, nextBackground);
29 Array.Resize(ref Main.backgroundHeight, nextBackground);
30 Array.Resize(ref Main.backgroundWidth, nextBackground);
31 Array.Resize(ref Main.backgroundLoaded, nextBackground);
32 foreach (string texture in backgrounds.Keys) {
33 int slot = backgrounds[texture];
34 Main.backgroundTexture[slot] = ModContent.GetTexture(texture);
35 Main.backgroundWidth[slot] = Main.backgroundTexture[slot].Width;
36 Main.backgroundHeight[slot] = Main.backgroundTexture[slot].Height;
37 Main.backgroundLoaded[slot] = true;
38 }
39 }
40
41 internal static void Unload() {
43 backgrounds.Clear();
44 }
45 }
46}
This is the class that keeps track of all modded background textures and their slots/IDs.
static int GetBackgroundSlot(string texture)
Returns the slot/ID of the background texture with the given name.
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
Definition: ModContent.cs:27
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
Definition: ModContent.cs:72