private void DrawSpriteResource(Icon icon, int orderIndex, Vector2f position) { int resourceId = icon.GetResourceId(orderIndex); Texture texture = GetTexture(resourceId); Sprite sprite = new Sprite(texture); ColorB color = icon.GetColor(orderIndex); sprite.Color = new Color(color.R, color.G, color.B, color.A); sprite.Position = position; _renderReceiver.DrawSprite(sprite); }
private void DrawCellObjects(Vector2Int cell) { TileObject[] objects = _scene.GetObjects(cell); foreach (var obj in objects) { Icon icon = obj.Icon; if (_layersVisibility[(int)obj.Layer]) { Vector2f sfmlPosition = WorldToSfml(cell, obj.Offset); for (int i = 0; i < icon.SpritesCount; i++) { DrawSpriteResource(icon, i, sfmlPosition); } } } }
public Bitmap GetEditorImage(TileObject instance) { Icon editorIcon = instance.EditorIcon; if (editorIcon == null) { return(null); } Texture texture = GetTexture(editorIcon.GetResourceId(0)); if (texture == null) { return(null); } Image image = texture.CopyToImage(); byte[] pixels = image.Pixels; int width = (int)image.Size.X; int height = (int)image.Size.Y; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); var boundsRect = new Rectangle(0, 0, width, height); BitmapData bmpData = bmp.LockBits(boundsRect, ImageLockMode.WriteOnly, bmp.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = bmpData.Stride * bmp.Height; var rgbValues = new byte[bytes]; Array.Copy(pixels, 0, rgbValues, 0, pixels.Length); Marshal.Copy(rgbValues, 0, ptr, bytes); bmp.UnlockBits(bmpData); return(bmp); }
public void Render(Vector2 iconPosition, Icon icon, TileObjectSpirit spirit) { for (int i = 0; i < icon.SpritesCount; i++) { Sprite sprite; if (spirit.Tag == null) { IconSpriteCache cache = new IconSpriteCache(); var resourceEntry = GameResources.Instance.GetEntry(icon.ResourceIds[i]); ColorB color = icon.Colors[i]; float scale = icon.Scales[i]; if (resourceEntry.LoadedValue == null) { byte[] textureBytes = resourceEntry.ToByteArray(); Texture texture = new Texture(textureBytes); resourceEntry.LoadedValue = texture; } sprite = new Sprite((Texture)resourceEntry.LoadedValue) { Color = new Color(color.R, color.G, color.B, color.A), Scale = new Vector2f(scale, scale) }; cache.Sprites.Add(sprite); spirit.Tag = cache; spirit.IconDirty = false; } if (spirit.IconDirty) { var resourceEntry = GameResources.Instance.GetEntry(icon.ResourceIds[i]); ColorB color = icon.Colors[i]; float scale = icon.Scales[i]; if (resourceEntry.LoadedValue == null) { byte[] textureBytes = resourceEntry.ToByteArray(); Texture texture = new Texture(textureBytes); resourceEntry.LoadedValue = texture; } sprite = new Sprite((Texture)resourceEntry.LoadedValue) { Color = new Color(color.R, color.G, color.B, color.A), Scale = new Vector2f(scale, scale) }; ((IconSpriteCache)spirit.Tag).Sprites[i] = sprite; spirit.IconDirty = false; } else { sprite = ((IconSpriteCache)spirit.Tag).Sprites[i]; } if (spirit.LocationDirty) { sprite.Position = new Vector2f(iconPosition.X * 32, iconPosition.Y * 32); spirit.LocationDirty = false; } _renderWindow.Draw(sprite); } }