/// <summary> /// 渲染当前层画面到LGraphics之上 /// </summary> /// /// <param name="g"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="sx"></param> /// <param name="sy"></param> /// <param name="width"></param> /// <param name="ty"></param> /// <param name="isLine"></param> /// <param name="mapTileWidth"></param> /// <param name="mapTileHeight"></param> public void Draw(GLEx g, int x, int y, int sx, int sy, int width, int height, bool isLine, int mapTileWidth, int mapTileHeight) { if (width == 0 || height == 0) { return; } if (lightingOn) { GLUtils.SetShadeModelSmooth(GLEx.GL); } this.tmxTileSet = null; this.mapTileSet = null; for (int tileset = 0; tileset < tmx.GetTileSetCount(); tileset++) { keyHashCode = 1; keyHashCode = LSystem.Unite(keyHashCode, tileset); keyHashCode = LSystem.Unite(keyHashCode, sx); keyHashCode = LSystem.Unite(keyHashCode, sy); keyHashCode = LSystem.Unite(keyHashCode, width); keyHashCode = LSystem.Unite(keyHashCode, height); keyHashCode = LSystem.Unite(keyHashCode, mapTileWidth); keyHashCode = LSystem.Unite(keyHashCode, mapTileHeight); keyHashCode = LSystem.Unite(keyHashCode, lightingOn); mapTileSet = (MapTileSet)CollectionUtils.Get(lazyMaps, keyHashCode); if (!isLightDirty && mapTileSet != null) { mapTileSet.cache.x = x; mapTileSet.cache.y = y; LTextureBatch.Commit(mapTileSet.texture, mapTileSet.cache); if (isLine) { tmx.Draw(g, x, y, sx, sy, width, height, index); } if (lightingOn) { GLUtils.SetShadeModelSmooth(GLEx.GL); } return; } for (int ty = 0; ty < height; ty++) { for (int tx = 0; tx < width; tx++) { if ((sx + tx < 0) || (sy + ty < 0)) { continue; } if ((sx + tx >= this.width) || (sy + ty >= this.height)) { continue; } if (data[sx + tx, sy + ty, 0] == tileset) { if (tmxTileSet == null) { tmxTileSet = tmx.GetTileSet(tileset); tmxTileSet.tiles.GLBegin(); } int sheetX = tmxTileSet .GetTileX(data[sx + tx, sy + ty, 1]); int sheetY = tmxTileSet .GetTileY(data[sx + tx, sy + ty, 1]); int tileOffsetY = tmxTileSet.tileHeight - mapTileHeight; cx = tx * mapTileWidth; cy = ty * mapTileHeight - tileOffsetY; if (lightingOn) { SetLightColor(cx / mapTileWidth, cy / mapTileHeight); } tmxTileSet.tiles .Draw(g, cx, cy, sheetX, sheetY, colors); } } } if (tmxTileSet != null) { tmxTileSet.tiles.GLEnd(); if (mapTileSet == null) { mapTileSet = new TMXLayer.MapTileSet(); } else { mapTileSet.texture = null; mapTileSet.cache.Dispose(); mapTileSet.cache = null; } mapTileSet.texture = tmxTileSet.tiles.GetTarget(); mapTileSet.cache = tmxTileSet.tiles.NewCache(); mapTileSet.cache.x = x; mapTileSet.cache.y = y; CollectionUtils.Put(lazyMaps, keyHashCode, mapTileSet); if (lightingOn) { GLUtils.SetShadeModelFlat(GLEx.GL); } if (isLine) { tmx.Draw(g, x, y, sx, sy, width, height, index); } isLightDirty = false; tmxTileSet = null; } } }
/// <summary> /// 渲染当前层画面到LGraphics之上 /// </summary> /// /// <param name="g"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="sx"></param> /// <param name="sy"></param> /// <param name="width0"></param> /// <param name="ty"></param> /// <param name="isLine"></param> /// <param name="mapTileWidth"></param> /// <param name="mapTileHeight"></param> public void Draw(GLEx g, int x, int y, int sx, int sy, int width0, int height0, bool isLine, int mapTileWidth, int mapTileHeight) { if (width0 == 0 || height0 == 0) { return; } if (lightingOn) { } this.tmxTileSet = null; for (int tileset = 0; tileset < tmx.GetTileSetCount(); tileset++) { for (int ty = 0; ty < height0; ty++) { for (int tx = 0; tx < width0; tx++) { if ((sx + tx < 0) || (sy + ty < 0)) { continue; } if ((sx + tx >= this.width) || (sy + ty >= this.height)) { continue; } if (data[sx + tx, sy + ty, 0] == tileset) { if (tmxTileSet == null) { tmxTileSet = tmx.GetTileSet(tileset); tmxTileSet.tiles.GLBegin(); } int sheetX = tmxTileSet .GetTileX(data[sx + tx, sy + ty, 1]); int sheetY = tmxTileSet .GetTileY(data[sx + tx, sy + ty, 1]); int tileOffsetY = tmxTileSet.tileHeight - mapTileHeight; cx = tx * mapTileWidth; cy = ty * mapTileHeight - tileOffsetY; if (lightingOn) { SetLightColor(cx / mapTileWidth, cy / mapTileHeight); } tmxTileSet.tiles .Draw(g, cx, cy, sheetX, sheetY); } } } if (tmxTileSet != null) { tmxTileSet.tiles.GLEnd(); if (lightingOn) { } if (isLine) { tmx.Draw(g, x, y, sx, sy, width0, height0, index); } isLightDirty = false; tmxTileSet = null; } } }