private static void drawImageLayer(Layer layer, xTile.Display.IDisplayDevice device, xTile.Dimensions.Rectangle viewport, int pixelZoom, Location offset, bool wrap = false) { Vector2 pos = Game1.GlobalToLocal(new Vector2(offset.X, offset.Y)); if (layer.Properties.ContainsKey("ParallaxX") || layer.Properties.ContainsKey("ParallaxY")) { Vector2 end = pos; if (layer.Properties.ContainsKey("OffestXReset")) { end.X = layer.Properties["OffestXReset"]; end.Y = layer.Properties["OffestYReset"]; } end = Game1.GlobalToLocal(end); Vector2 start = new Vector2(layer.Properties["StartX"], layer.Properties["StartY"]); Vector2 dif = start - end; if (layer.Properties.ContainsKey("ParallaxX")) { pos.X += ((float.Parse(layer.Properties["ParallaxX"]) * dif.X) / 100f) - dif.X; } if (layer.Properties.ContainsKey("ParallaxY")) { pos.Y += ((float.Parse(layer.Properties["ParallaxY"]) * dif.Y) / 100f) - dif.Y; } } if (!wrap) { layer.Draw(device, viewport, offset, wrap, pixelZoom); return; } if (layer.GetTileSheetForImageLayer() is TileSheet ts && PyDisplayDevice.Instance is PyDisplayDevice sDevice && sDevice.GetTexture(ts) is Texture2D texture && layer.GetOpacity() is float opacity) { Color color = Color.White; if (layer.GetColor() is TMXColor c) { color = new Color(c.R, c.G, c.B, c.A); } var vp = new Microsoft.Xna.Framework.Rectangle(Game1.viewport.X, Game1.viewport.Y, Game1.viewport.Width, Game1.viewport.Height); Microsoft.Xna.Framework.Rectangle dest = new Microsoft.Xna.Framework.Rectangle((int)pos.X, (int)pos.Y, texture.Width * Game1.pixelZoom, texture.Height * Game1.pixelZoom); Vector2 s = pos; while (s.X > (vp.X - (dest.Width * 2)) || s.Y > (vp.Y - (dest.Height * 2))) { s.X -= dest.Width; s.Y -= dest.Height; } Vector2 e = new Vector2(vp.X + vp.Width + (dest.Width * 2), vp.Height + vp.Y + (dest.Height * 2)); for (float x = s.X; x <= e.X; x += dest.Width) { for (Microsoft.Xna.Framework.Rectangle n = new Microsoft.Xna.Framework.Rectangle((int)x, (int)s.Y, dest.Width, dest.Height); n.Y <= e.Y; n.Y += dest.Height) { if ((layer.Properties["WrapAround"] != "Y" || n.X == dest.X) && (layer.Properties["WrapAround"] != "X" || n.Y == dest.Y)) { Game1.spriteBatch.Draw(texture, n, color * opacity); } } } } }
private static void drawImageLayer(Layer layer, xTile.Display.IDisplayDevice device, xTile.Dimensions.Rectangle viewport, int pixelZoom, Location offset, bool wrap = false) { string ts = "zImageSheet_" + layer.Id; if (layer.Properties.ContainsKey("UseImageFrom")) { ts = "zImageSheet_" + layer.Properties["UseImageFrom"]; } Texture2D texture = null; if (ImageLayerCache.ContainsKey(ts)) { texture = ImageLayerCache[ts]; } else { texture = Helper.Content.Load <Texture2D>(layer.Map.GetTileSheet(ts).ImageSource, ContentSource.GameContent); ImageLayerCache.Add(ts, texture); } Vector2 pos = Game1.GlobalToLocal(new Vector2(offset.X, offset.Y)); if (layer.Properties.ContainsKey("ParallaxX") || layer.Properties.ContainsKey("ParallaxY")) { Vector2 end = pos; if (layer.Properties.ContainsKey("OffestXReset")) { end.X = layer.Properties["OffestXReset"]; end.Y = layer.Properties["OffestYReset"]; } end = Game1.GlobalToLocal(end); Vector2 start = new Vector2(layer.Properties["StartX"], layer.Properties["StartY"]); Vector2 dif = start - end; if (layer.Properties.ContainsKey("ParallaxX")) { pos.X += ((float.Parse(layer.Properties["ParallaxX"]) * dif.X) / 100f) - dif.X; } if (layer.Properties.ContainsKey("ParallaxY")) { pos.Y += ((float.Parse(layer.Properties["ParallaxY"]) * dif.Y) / 100f) - dif.Y; } } Color color = Color.White; if (layer.Properties.ContainsKey("Color")) { string[] c = layer.Properties["Color"].ToString().Split(' '); color = new Color(int.Parse(c[0]), int.Parse(c[1]), int.Parse(c[2]), c.Length > 3 ? int.Parse(c[3]) : 255); } Microsoft.Xna.Framework.Rectangle dest = new Microsoft.Xna.Framework.Rectangle((int)pos.X, (int)pos.Y, texture.Width * Game1.pixelZoom, texture.Height * Game1.pixelZoom); if (!wrap) { Game1.spriteBatch.Draw(texture, dest, color * (float)float.Parse(layer.Properties["opacity"])); } var vp = new Microsoft.Xna.Framework.Rectangle(Game1.viewport.X, Game1.viewport.Y, Game1.viewport.Width, Game1.viewport.Height); if (wrap) { Vector2 s = pos; while (s.X > (vp.X - (dest.Width * 2)) || s.Y > (vp.Y - (dest.Height * 2))) { s.X -= dest.Width; s.Y -= dest.Height; } Vector2 e = new Vector2(vp.X + vp.Width + (dest.Width * 2), vp.Height + vp.Y + (dest.Height * 2)); for (float x = s.X; x <= e.X; x += dest.Width) { for (Microsoft.Xna.Framework.Rectangle n = new Microsoft.Xna.Framework.Rectangle((int)x, (int)s.Y, dest.Width, dest.Height); n.Y <= e.Y; n.Y += dest.Height) { if ((layer.Properties["WrapAround"] != "Y" || n.X == dest.X) && (layer.Properties["WrapAround"] != "X" || n.Y == dest.Y)) { Game1.spriteBatch.Draw(texture, n, color * (float)float.Parse(layer.Properties["opacity"])); } } } } }
public static void drawLayer(Layer layer, xTile.Display.IDisplayDevice device, xTile.Dimensions.Rectangle viewport, int pixelZoom, Location offset, bool wrap = false) { if (layer.Properties.ContainsKey("DrawConditions") && !layer.Properties.ContainsKey("DrawConditionsResult") && Game1.currentLocation is GameLocation gl && gl.Map is Map m) { PyUtils.checkDrawConditions(m); } if (layer.Properties.ContainsKey("DrawConditions") && (!layer.Properties.ContainsKey("DrawConditionsResult") || layer.Properties["DrawConditionsResult"] != "T")) { return; } if (!layer.Properties.ContainsKey("OffestXReset")) { layer.Properties["OffestXReset"] = offset.X; layer.Properties["OffestYReset"] = offset.Y; } if (!layer.Properties.ContainsKey("StartX")) { Vector2 local = Game1.GlobalToLocal(new Vector2(offset.X, offset.Y)); layer.Properties["StartX"] = local.X; layer.Properties["StartY"] = local.Y; } if (layer.Properties.ContainsKey("AutoScrollX")) { string[] ax = layer.Properties["AutoScrollX"].ToString().Split(','); int cx = int.Parse(ax[0]); int mx = 1; if (ax.Length > 1) { mx = int.Parse(ax[1]); } if (cx < 0) { mx *= -1; } if (Game1.currentGameTime.TotalGameTime.Ticks % cx == 0) { offset.X += mx; } } if (layer.Properties.ContainsKey("AutoScrollY")) { string[] ay = layer.Properties["AutoScrollY"].ToString().Split(','); int cy = int.Parse(ay[0]); int my = 1; if (ay.Length > 1) { my = int.Parse(ay[1]); } if (cy < 0) { my *= -1; } if (Game1.currentGameTime.TotalGameTime.Ticks % cy == 0) { offset.Y += my; } } layer.SetOffset(offset); if (layer.Properties.ContainsKey("tempOffsetx") && layer.Properties.ContainsKey("tempOffsety")) { offset = new Location(int.Parse(layer.Properties["tempOffsetx"]), int.Parse(layer.Properties["tempOffsety"])); } if (layer.IsImageLayer()) { drawImageLayer(layer, offset, wrap); } else { layer.Draw(device, viewport, offset, wrap, pixelZoom); } }
public static void drawLayer(Layer layer, xTile.Display.IDisplayDevice device, xTile.Dimensions.Rectangle viewport, int pixelZoom, Location offset, bool wrap = false) { if (layer.Properties.ContainsKey("DrawConditions") && (!layer.Properties.ContainsKey("DrawConditionsResult") || layer.Properties["DrawConditionsResult"] != "T")) { return; } if (layer.Properties.ContainsKey("offsetx") && layer.Properties.ContainsKey("offsety")) { offset = new Location(int.Parse(layer.Properties["offsetx"]), int.Parse(layer.Properties["offsety"])); if (!layer.Properties.ContainsKey("OffestXReset")) { layer.Properties["OffestXReset"] = offset.X; layer.Properties["OffestYReset"] = offset.Y; } } if (!layer.Properties.ContainsKey("StartX")) { Vector2 local = Game1.GlobalToLocal(new Vector2(offset.X, offset.Y)); layer.Properties["StartX"] = local.X; layer.Properties["StartY"] = local.Y; } if (layer.Properties.ContainsKey("AutoScrollX")) { string[] ax = layer.Properties["AutoScrollX"].ToString().Split(','); int cx = int.Parse(ax[0]); int mx = 1; if (ax.Length > 1) { mx = int.Parse(ax[1]); } if (cx < 0) { mx *= -1; } if (Game1.currentGameTime.TotalGameTime.Ticks % cx == 0) { offset.X += mx; } } if (layer.Properties.ContainsKey("AutoScrollY")) { string[] ay = layer.Properties["AutoScrollY"].ToString().Split(','); int cy = int.Parse(ay[0]); int my = 1; if (ay.Length > 1) { my = int.Parse(ay[1]); } if (cy < 0) { my *= -1; } if (Game1.currentGameTime.TotalGameTime.Ticks % cy == 0) { offset.Y += my; } } layer.Properties["offsetx"] = offset.X; layer.Properties["offsety"] = offset.Y; bool resetColor = false; if (layer.Properties.ContainsKey("tempOffsetx") && layer.Properties.ContainsKey("tempOffsety")) { offset = new Location(int.Parse(layer.Properties["tempOffsetx"]), int.Parse(layer.Properties["tempOffsety"])); } if (layer.Properties.ContainsKey("isImageLayer")) { drawImageLayer(layer, offset, wrap); } else { resetColor = setColorForTiledLayer(layer); layer.Draw(device, viewport, offset, wrap, pixelZoom); } if (resetColor) { (Game1.mapDisplayDevice as XnaDisplayDevice).ModulationColour = Color.White; } }