Add MrGameEng.Tilemaps: code-built tile grids rendered through the batcher
CI / build-test (push) Failing after 1m4s
CI / build-test (push) Failing after 1m4s
TileSet maps ids to texture regions with tints (0 = empty), TileGrid is a bounds-checked dense ushort grid, and the Tilemap component places a grid in the world per render layer. UseTilemaps() inserts TilemapRenderSystem before the flush; it submits only the camera-visible cell range (TilemapMath.VisibleCells), so frame cost scales with the screen, not the grid. Demonstrated in the sample as a checkerboard floor; Tiled loading stays on the roadmap on top of this API.
This commit is contained in:
@@ -7,6 +7,7 @@ using MrGameEng.Core;
|
||||
using MrGameEng.DevConsole;
|
||||
using MrGameEng.Graphics;
|
||||
using MrGameEng.Input;
|
||||
using MrGameEng.Tilemaps;
|
||||
using MrGameEng.UI;
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
@@ -32,6 +33,7 @@ public sealed class MainScene : Scene
|
||||
|
||||
var renderer = this.UseRenderer2D(new Renderer2DOptions { VirtualResolution = new Point(1280, 720) });
|
||||
SampleLayers.EnsureRegistered(renderer);
|
||||
this.UseTilemaps();
|
||||
|
||||
var playerTexture = assets.Load(GameAssets.Textures.Player);
|
||||
var shapesTexture = assets.Load(GameAssets.Textures.Shapes);
|
||||
@@ -50,6 +52,26 @@ public sealed class MainScene : Scene
|
||||
new Texture2DRegion(shapesTexture, new Rectangle(32, 32, 32, 32)),
|
||||
};
|
||||
|
||||
// Тайловая площадка под стартовой зоной: шахматный пол, строится кодом из TileSet/TileGrid.
|
||||
// Видимые клетки сабмитятся каждый кадр; Depth -10 кладёт пол под декорации.
|
||||
var floorTiles = new TileSet();
|
||||
var floorA = floorTiles.Add(shapeRegions[0], new Color(70, 75, 95));
|
||||
var floorB = floorTiles.Add(shapeRegions[2], new Color(55, 60, 78));
|
||||
var floorGrid = new TileGrid(24, 14);
|
||||
for (var y = 0; y < floorGrid.Height; y++)
|
||||
{
|
||||
for (var x = 0; x < floorGrid.Width; x++)
|
||||
{
|
||||
floorGrid[x, y] = (x + y) % 2 == 0 ? floorA : floorB;
|
||||
}
|
||||
}
|
||||
|
||||
Store.CreateEntity(new Tilemap(floorGrid, floorTiles, tileSize: 48f)
|
||||
{
|
||||
Origin = new Vector2(-24 * 24f, -14 * 24f),
|
||||
Depth = -10f,
|
||||
});
|
||||
|
||||
// Декорации по всему миру: уезжаешь камерой — попадают под culling (см. заголовок окна).
|
||||
var random = new Random(42);
|
||||
for (var i = 0; i < DecorCount; i++)
|
||||
|
||||
Reference in New Issue
Block a user