https://github.com/simulation-tree/textures
Images and atlases of sprites
https://github.com/simulation-tree/textures
csharp dotnet images textures
Last synced: 5 months ago
JSON representation
Images and atlases of sprites
- Host: GitHub
- URL: https://github.com/simulation-tree/textures
- Owner: simulation-tree
- Created: 2024-07-05T01:44:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-24T03:03:39.000Z (9 months ago)
- Last Synced: 2025-09-24T05:21:15.535Z (9 months ago)
- Topics: csharp, dotnet, images, textures
- Language: C#
- Homepage:
- Size: 91.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Textures
Definitions for images, and for atlases with their sprites.
### Importing images
```cs
Texture texture = new(world, "*/texture.png");
while (!texture.IsCompliant)
{
simulator.Broadcast(new DataUpdate()); //to load the bytes
simulator.Broadcast(new TextureUpdate()); //load import the texture from the bytes
}
Assert.That(texture.Width, Is.EqualTo(1024));
Assert.That(texture.Height, Is.EqualTo(1024));
ReadOnlySpan pixels = texture.Pixels;
Assert.That(pixels.Length, Is.EqualTo(1024 * 1024));
```
### Evaluating pixels
When textures are loaded, their colours can be evaluated at floating point coordinates, or exact coordinates:
```cs
Color color = texture.Evaluate(0.5f, 0.5f);
Pixel exactPixel = texture[512, 512];
```
### Creating atlases from inputs
An `AtlasTexture` can be created from a series of sprites, each with individual pixel data into
the smallest possible texture:
```cs
Span sprites = stackalloc AtlasTexture.InputSprite[1];
AtlasTexture.InputSprite firstSprite = new("firstSprite", 32, 32);
Span firstSpritePixels = firstSprite.Pixels;
firstSpritePixels.Fill(new Pixel(255, 0, 0, 255));
sprites[0] = firstSprite;
AtlasTexture atlas = new(world, sprites);
if (atlas.TryGetSprite("firstSprite", out AtlasSprite sprite))
{
Vector4 region = sprite.region;
}
Console.WriteLine($"Atlas texture size: {atlas.Width}x{atlas.Height}");
```