public void Read(BinaryReader r, bool affine, ref ushort affinePrefix, int tileCount) { if (affine) { PaletteIndex = 0; FlipFlags = FlipFlags.None; ushort index = r.ReadByte(); TileIndex = (ushort)(index + affinePrefix); if (index == 0xFF) { affinePrefix += 0x100; } if (affinePrefix >= tileCount) { affinePrefix = 0; } } else { ushort val = r.ReadUInt16(); TileIndex = (ushort)(val & 0x3FF); PaletteIndex = (byte)((val >> 12) & 0xF); FlipFlags = FlipFlags.None; if ((val & 0x400) > 0) { FlipFlags |= FlipFlags.Horizontal; } if ((val & 0x800) > 0) { FlipFlags |= FlipFlags.Vertical; } } }
public void SetFlipFlags(Vector3Int pos3, FlipFlags flags) { if (flags != 0) { m_TilePositionFlipFlags.Add(pos3, flags); } }
/// <summary> /// Draws unicode (UTF-16) characters as sprites using the specified <see cref="BitmapFont" />, text /// <see cref="string" />, transform <see cref="Matrix2D" /> and optional <see cref="Color" />, origin /// <see cref="Vector2" />, <see cref="FlipFlags" />, and depth <see cref="float" />. /// </summary> /// <param name="bitmapFont">The <see cref="BitmapFont" />.</param> /// <param name="text">The text <see cref="string" />.</param> /// <param name="transformMatrix">The transform <see cref="Matrix2D" />.</param> /// <param name="color"> /// The <see cref="Color" />. Use <code>null</code> to use the default /// <see cref="Color.White" />. /// </param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0f</code></param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="bitmapFont" /> is null or <paramref name="text" /> is null.</exception> public void DrawString(BitmapFont bitmapFont, string text, ref Matrix2D transformMatrix, Color?color = null, FlipFlags flags = FlipFlags.None, float depth = 0f) { EnsureHasBegun(); if (bitmapFont == null) { throw new ArgumentNullException(nameof(bitmapFont)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } var glyphs = bitmapFont.GetGlyphs(text); foreach (var glyph in glyphs) { var transform1Matrix = transformMatrix; transform1Matrix.M31 += glyph.Position.X; transform1Matrix.M32 += glyph.Position.Y; var texture = glyph.FontRegion.TextureRegion.Texture; var bounds = texture.Bounds; DrawSprite(texture, ref transform1Matrix, ref bounds, color, flags, depth); } }
/// <summary> /// Draws unicode (UTF-16) characters as sprites using the specified <see cref="BitmapFont" />, text /// <see cref="string" />, position <see cref="Vector2" /> and optional <see cref="Color" />, rotation /// <see cref="float" />, origin <see cref="Vector2" />, scale <see cref="Vector2" /> <see cref="FlipFlags" />, and /// depth <see cref="float" />. /// </summary> /// <param name="bitmapFont">The <see cref="BitmapFont" />.</param> /// <param name="text">The text <see cref="string" />.</param> /// <param name="position">The position <see cref="Vector2" />.</param> /// <param name="color"> /// The <see cref="Color" />. Use <code>null</code> to use the default /// <see cref="Color.White" />. /// </param> /// <param name="rotation"> /// The angle <see cref="float" /> (in radians) to rotate each sprite about its <paramref name="origin" />. The default /// value is <code>0f</code>. /// </param> /// <param name="origin"> /// The origin <see cref="Vector2" />. Use <code>null</code> to use the default /// <see cref="Vector2.Zero" />. /// </param> /// <param name="scale"> /// The scale <see cref="Vector2" />. Use <code>null</code> to use the default /// <see cref="Vector2.One" />. /// </param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0f</code></param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="bitmapFont" /> is null or <paramref name="text" /> is null.</exception> public void DrawString(BitmapFont bitmapFont, string text, Vector2 position, Color?color = null, float rotation = 0f, Vector2?origin = null, Vector2?scale = null, FlipFlags flags = FlipFlags.None, float depth = 0f) { Matrix2.CreateFrom(position, rotation, scale, origin, out Matrix2 matrix); DrawString(bitmapFont, text, ref matrix, color, flags, depth); }
public Matrix4x4 GetTransformMatrix(FlipFlags ff) { var inversePPU = 1.0f / m_Sprite.pixelsPerUnit; var offset = new Vector2(m_TileOffsetX * inversePPU, -m_TileOffsetY * inversePPU); var matOffset = Matrix4x4.Translate(offset); if (ff == FlipFlags.None) { return(matOffset); } bool flipHorizontal = (ff & FlipFlags.Horizontal) != 0; bool flipVertical = (ff & FlipFlags.Vertical) != 0; bool flipDiagonal = (ff & FlipFlags.Diagonal) != 0; float width = m_Width * inversePPU; float height = m_Height * inversePPU; var tileCenter = new Vector2(width, height) * 0.5f; Matrix4x4 matTransIn = Matrix4x4.identity; Matrix4x4 matFlip = Matrix4x4.identity; Matrix4x4 matTransOut = Matrix4x4.identity; // Go to the tile center matTransIn = Matrix4x4.Translate(-tileCenter); // Do the flips if (flipHorizontal) { matFlip *= HorizontalFlipMatrix; } if (flipVertical) { matFlip *= VerticalFlipMatrix; } if (flipDiagonal) { matFlip *= DiagonalFlipMatrix; } // Go out of the tile center if (!flipDiagonal) { matTransOut = Matrix4x4.Translate(tileCenter); } else { float diff = (m_Height - m_Width) * 0.5f * inversePPU; tileCenter.x += diff; tileCenter.y -= diff; matTransOut = Matrix4x4.Translate(tileCenter); } // Put it all together return(matOffset * matTransOut * matFlip * matTransIn); }
/// <summary> /// Draws a <see cref="Texture" /> using the specified transform <see cref="Matrix2D" /> and an optional /// <see cref="Color" />, origin <see cref="Vector2" />, <see cref="FlipFlags" />, and depth <see cref="float" />. /// </summary> /// <param name="texture">The <see cref="Texture" />.</param> /// <param name="transformMatrix">The transform <see cref="Matrix2D" />.</param> /// <param name="color">The <see cref="Color" />. Use <code>null</code> to use the default <see cref="Color.White" />.</param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0</code>.</param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="texture" /> is null.</exception> public void DrawTexture(Texture2D texture, ref Matrix2D transformMatrix, Color?color = null, FlipFlags flags = FlipFlags.None, float depth = 0) { var rectangle = default(Rectangle); _geometryBuilder.BuildSprite(_vertexCount, ref transformMatrix, texture, ref rectangle, color, flags, depth); EnqueueBuiltGeometry(texture, depth); }
/// <summary> /// Draws unicode (UTF-16) characters as sprites using the specified <see cref="BitmapFont" />, text /// <see cref="StringBuilder" />, position <see cref="Vector2" /> and optional <see cref="Color" />, rotation /// <see cref="float" />, origin <see cref="Vector2" />, scale <see cref="Vector2" /> <see cref="FlipFlags" />, and /// depth <see cref="float" />. /// </summary> /// <param name="bitmapFont">The <see cref="BitmapFont" />.</param> /// <param name="text">The text <see cref="string" />.</param> /// <param name="position">The position <see cref="Vector2" />.</param> /// <param name="color"> /// The <see cref="Color" />. Use <code>null</code> to use the default /// <see cref="Color.White" />. /// </param> /// <param name="rotation"> /// The angle <see cref="float" /> (in radians) to rotate each sprite about its <paramref name="origin" />. The default /// value is <code>0f</code>. /// </param> /// <param name="origin"> /// The origin <see cref="Vector2" />. Use <code>null</code> to use the default /// <see cref="Vector2.Zero" />. /// </param> /// <param name="scale"> /// The scale <see cref="Vector2" />. Use <code>null</code> to use the default /// <see cref="Vector2.One" />. /// </param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0f</code></param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="bitmapFont" /> is null or <paramref name="text" /> is null.</exception> public void DrawString(BitmapFont bitmapFont, StringBuilder text, Vector2 position, Color?color = null, float rotation = 0f, Vector2?origin = null, Vector2?scale = null, FlipFlags flags = FlipFlags.None, float depth = 0f) { Matrix2D transformMatrix; Matrix2D.CreateFrom(position, rotation, scale, origin, out transformMatrix); DrawString(bitmapFont, text, ref transformMatrix, color, flags, depth); }
public TileIdMath(uint importedTileId) { m_ImportedTileId = importedTileId; m_FlipFlags = 0; m_FlipFlags |= HasHorizontalFlip ? FlipFlags.Horizontal : 0; m_FlipFlags |= HasVerticalFlip ? FlipFlags.Vertical : 0; m_FlipFlags |= HasDiagonalFlip ? FlipFlags.Diagonal : 0; }
public TileId(uint gid) { originalGid = gid; flipFlags = 0; flipFlags |= IsFlippedHorizontal() ? FlipFlags.Horizontal : 0; flipFlags |= IsFlippedVertical() ? FlipFlags.Vertical : 0; flipFlags |= IsFlippedDiagonal() ? FlipFlags.Diagonal : 0; flipFlags |= IsFlippedHexagonal120() ? FlipFlags.Hexagonal120 : 0; }
public TextSprite(TextSprite clone) { _name = clone._name + "_clone"; _transform = clone._transform; _tint = clone._tint; _hAlign = clone.HorizontalAlignment; _vAlign = clone.VerticalAlignment; _font = clone._font; _text = clone._text; _size = clone._size; _flipMode = clone._flipMode; }
public FrameSprite(FrameSprite clone) : base() { _name = clone._name + "_clone"; _frame = clone._frame; _destinationRect = clone._destinationRect; _transform = clone._transform; _origin = clone._origin; _tint = clone._tint; _paralaxFactor = clone._paralaxFactor; _paralaxEnabled = clone._paralaxEnabled; _flipMode = clone._flipMode; }
/// <summary> /// Draws unicode (UTF-16) characters as sprites using the specified <see cref="BitmapFont" />, text /// <see cref="string" />, transform <see cref="Matrix2D" /> and optional <see cref="Color" />, origin /// <see cref="Vector2" />, <see cref="FlipFlags" />, and depth <see cref="float" />. /// </summary> /// <param name="bitmapFont">The <see cref="BitmapFont" />.</param> /// <param name="text">The text <see cref="string" />.</param> /// <param name="transformMatrix">The transform <see cref="Matrix2D" />.</param> /// <param name="color"> /// The <see cref="Color" />. Use <code>null</code> to use the default /// <see cref="Color.White" />. /// </param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0f</code></param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="bitmapFont" /> is null or <paramref name="text" /> is null.</exception> public void DrawString(BitmapFont bitmapFont, string text, ref Matrix2D transformMatrix, Color?color = null, FlipFlags flags = FlipFlags.None, float depth = 0f) { EnsureHasBegun(); if (bitmapFont == null) { throw new ArgumentNullException(nameof(bitmapFont)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } var lineSpacing = bitmapFont.LineHeight; var offset = new Vector2(0, 0); for (var i = 0; i < text.Length;) { int character; if (char.IsLowSurrogate(text[i])) { character = char.ConvertToUtf32(text[i - 1], text[i]); i += 2; } else if (char.IsHighSurrogate(text[i])) { character = char.ConvertToUtf32(text[i], text[i - 1]); i += 2; } else { character = text[i]; i += 1; } // ReSharper disable once SwitchStatementMissingSomeCases switch (character) { case '\r': continue; case '\n': offset.X = 0; offset.Y += lineSpacing; continue; } var fontRegion = bitmapFont.GetCharacterRegion(character); if (fontRegion == null) { continue; } var transform1Matrix = transformMatrix; transform1Matrix.M31 += offset.X + fontRegion.XOffset; transform1Matrix.M32 += offset.Y + fontRegion.YOffset; var textureRegion = fontRegion.TextureRegion; var bounds = textureRegion.Bounds; DrawSprite(textureRegion.Texture, ref transform1Matrix, ref bounds, color, flags, depth); offset.X += i != text.Length - 1 ? fontRegion.XAdvance + bitmapFont.LetterSpacing : fontRegion.XOffset + fontRegion.Width; } }
/// <summary> /// Draws a sprite using a specified <see cref="Texture" />, transform <see cref="Matrix2D" />, source /// <see cref="Rectangle" />, and an optional /// <see cref="Color" />, origin <see cref="Vector2" />, <see cref="FlipFlags" />, and depth <see cref="float" />. /// </summary> /// <param name="texture">The <see cref="Texture" />.</param> /// <param name="transformMatrix">The transform <see cref="Matrix2D" />.</param> /// <param name="sourceRectangle"> /// The texture region <see cref="Rectangle" /> of the <paramref name="texture" />. Use /// <code>null</code> to use the entire <see cref="Texture2D" />. /// </param> /// <param name="color">The <see cref="Color" />. Use <code>null</code> to use the default <see cref="Color.White" />.</param> /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param> /// <param name="depth">The depth <see cref="float" />. The default value is <code>0</code>.</param> /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception> /// <exception cref="ArgumentNullException"><paramref name="texture" /> is null.</exception> public void DrawSprite(Texture2D texture, ref Matrix2D transformMatrix, ref Rectangle sourceRectangle, Color?color = null, FlipFlags flags = FlipFlags.None, float depth = 0) { _geometryBuilder.BuildSprite(_vertexCount, ref transformMatrix, texture, ref sourceRectangle, color, flags, depth); EnqueueBuiltGeometry(texture, depth); }
public void GetTRS(FlipFlags flags, MapOrientation orientation, out Vector3 xfTranslate, out Vector3 xfRotate, out Vector3 xfScale) { float inversePPU = 1.0f / m_Sprite.pixelsPerUnit; float width = m_Width * inversePPU; float height = m_Height * inversePPU; bool flippedHorizontally = FlipFlagsMask.FlippedHorizontally(flags); bool flippedVertically = FlipFlagsMask.FlippedVertically(flags); bool rotatedDiagonally = FlipFlagsMask.RotatedDiagonally(flags); bool rotatedHexagonally120 = FlipFlagsMask.RotatedHexagonally120(flags); xfTranslate = Vector3.zero; xfRotate = Vector3.zero; xfScale = Vector3.one; if (flags != FlipFlags.None) { if (orientation == MapOrientation.Hexagonal) { if (rotatedDiagonally) { xfRotate.z -= 60; } if (rotatedHexagonally120) { xfRotate.z -= 120; } } else if (rotatedDiagonally) { xfRotate.z = -90.0f; flippedHorizontally = FlipFlagsMask.FlippedVertically(flags); flippedVertically = !FlipFlagsMask.FlippedHorizontally(flags); } xfScale.x = flippedHorizontally ? -1.0f : 1.0f; xfScale.y = flippedVertically ? -1.0f : 1.0f; var matScale = Matrix4x4.Scale(xfScale); var matRotate = Matrix4x4.Rotate(Quaternion.Euler(xfRotate)); if (orientation == MapOrientation.Hexagonal) { // Hex tiles use the center of the tile for transforms var anchor = new Vector3(width * 0.5f, height * 0.5f); var transformed = matScale.MultiplyPoint(anchor); transformed = matRotate.MultiplyPoint(transformed); xfTranslate.x = anchor.x - transformed.x; xfTranslate.y = anchor.y - transformed.y; } else { // Mulitply the corners for our tile against rotation and scale matrices to see what our translation should be to get the tile back to the bottom-left origin var points = new Vector3[] { new Vector3(0, height, 0), new Vector3(width, height, 0), new Vector3(width, 0, 0), }; points = points.Select(p => matScale.MultiplyPoint(p)).ToArray(); points = points.Select(p => matRotate.MultiplyPoint(p)).ToArray(); var minX = points.Select(p => p.x).Min(); var minY = points.Select(p => p.y).Min(); xfTranslate.x = -minX; xfTranslate.y = -minY; } } // Each tile may have an additional offset xfTranslate.x += m_TileOffsetX * inversePPU; xfTranslate.y -= m_TileOffsetY * inversePPU; }
public void GetTRS(FlipFlags flags, out Vector3 trans, out Vector3 rot, out Vector3 scale) { float inversePPU = 1.0f / m_Sprite.pixelsPerUnit; float width = m_Width * inversePPU; float height = m_Height * inversePPU; switch (flags) { // diagonal case FlipFlags.D__: trans = new Vector3(height, width, 0); rot = new Vector3(0, 0, -90); scale = new Vector3(1, -1, 1); break; // diagonal-vertical case FlipFlags.DV_: trans = new Vector3(height, 0, 0); rot = new Vector3(0, 0, 90); scale = Vector3.one; break; // diagonal-horizontal case FlipFlags.D_H: trans = new Vector3(0, width, 0); rot = new Vector3(0, 0, -90); scale = Vector3.one; break; // diagonal-vertical-horizontal case FlipFlags.DVH: trans = Vector3.zero; rot = new Vector3(0, 0, 90); scale = new Vector3(1, -1, 1); break; // vertical case FlipFlags._V_: trans = new Vector3(0, height, 0); rot = Vector3.zero; scale = new Vector3(1, -1, 1); break; // vertical-horizontal case FlipFlags._VH: trans = new Vector3(width, height, 0); rot = Vector3.zero; scale = new Vector3(-1, -1, 1); break; // horizontal case FlipFlags.__H: trans = new Vector3(width, 0, 0); rot = Vector3.zero; scale = new Vector3(-1, 1, 1); break; default: trans = Vector3.zero; rot = Vector3.zero; scale = Vector3.one; break; } // Each tile may have an additional offset trans.x += m_TileOffsetX * inversePPU; trans.y -= m_TileOffsetY * inversePPU; }
public static bool RotatedDiagonally(FlipFlags flags) { return((flags & FlipFlags.Diagonal) != 0); }
protected virtual void SetFlipMode(FlipFlags flipMode) { _flipMode = flipMode; }
/// <summary> /// Performs a bit-block-transfer from the source brush to /// the destination brush, applying the specified paletteIndex. /// Any pixels with a value of zero will be rendered transparently. /// This overload specifies a pixel location instead of a tile location. /// </summary> /// <param name="tile">The count of the tile to be used from the source brush</param> /// <param name="destX">The x-coordinate to draw to.</param> /// <param name="destY">The y-coordinate to draw to.</param> /// <param name="pal">The paletteIndex to use.</param> /// <remarks>The paletteIndex specified will work for the range 0 through 31 if the source /// brush is formatted correctly, but for NES screen rendering typically only the first four /// palettes will be used.</remarks> /// <param name="flip">T FlipFlags value indicating how to flip the tile.</param> public void BlitTileTransparent_Pixel(int tile, int destX, int destY, byte pal, FlipFlags flip) { int baseTileOffset = tile * 8; int destBaseOffset = destX + destY * DestScanWidth; int screenInc = 1; int screenAdj = 0; if ((flip & FlipFlags.Horizontal) == FlipFlags.Horizontal) { screenInc = -1; screenAdj = 7; } byte paldiff = (byte)(pal * 4); for (int row = 0; row < 8; row++) { int screenDataOffset = destBaseOffset + row * DestScanWidth + screenAdj; int tileDataOffset; if ((flip & FlipFlags.Vertical) == FlipFlags.Vertical) { tileDataOffset = baseTileOffset + (7 - row) * SourceScanWidth; // Tile pixel data offset } else { tileDataOffset = baseTileOffset + row * SourceScanWidth; // Tile pixel data offset } // Render a single pixel (this code is repeated eight // times instead using a loop as a speed optimization). if (_sourceData[tileDataOffset] != 0) // If pixel is not transparent { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); // render it } // Seek to next pixel screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } screenDataOffset += screenInc; tileDataOffset++; if (_sourceData[tileDataOffset] != 0) { _destData[screenDataOffset] = (byte)(_sourceData[tileDataOffset] | paldiff); } } }
public Matrix4x4 GetTransformMatrix(FlipFlags ff, MapOrientation orientation) { var inversePPU = 1.0f / m_Sprite.pixelsPerUnit; var offset = new Vector2(m_TileOffsetX * inversePPU, -m_TileOffsetY * inversePPU); var matOffset = Matrix4x4.Translate(offset); if (ff == FlipFlags.None) { return(matOffset); } bool flipHorizontal = FlipFlagsMask.FlippedHorizontally(ff); bool flipVertical = FlipFlagsMask.FlippedVertically(ff); bool flipDiagonal = FlipFlagsMask.RotatedDiagonally(ff); bool rotateHex120 = FlipFlagsMask.RotatedHexagonally120(ff); float width = m_Width * inversePPU; float height = m_Height * inversePPU; var tileCenter = new Vector2(width, height) * 0.5f; Matrix4x4 matTransIn = Matrix4x4.identity; Matrix4x4 matFlip = Matrix4x4.identity; Matrix4x4 matTransOut = Matrix4x4.identity; // Go to the tile center matTransIn = Matrix4x4.Translate(-tileCenter); if (orientation == MapOrientation.Hexagonal) { if (flipDiagonal) { matFlip *= Rotate60Matrix; } if (rotateHex120) { matFlip *= Rotate120Matrix; } if (flipHorizontal) { matFlip *= HorizontalFlipMatrix; } if (flipVertical) { matFlip *= VerticalFlipMatrix; } matTransOut = Matrix4x4.Translate(tileCenter); } else { if (flipHorizontal) { matFlip *= HorizontalFlipMatrix; } if (flipVertical) { matFlip *= VerticalFlipMatrix; } if (flipDiagonal) { matFlip *= DiagonalFlipMatrix; } // Go out of the tile center if (!flipDiagonal) { matTransOut = Matrix4x4.Translate(tileCenter); } else { // Compensate for width and height being different dimensions float diff = (height - width) * 0.5f; tileCenter.x += diff; tileCenter.y -= diff; matTransOut = Matrix4x4.Translate(tileCenter); } } // Put it all together return(matOffset * matTransOut * matFlip * matTransIn); }
public static bool FlippedHorizontally(FlipFlags flags) { return((flags & FlipFlags.Horizontal) != 0); }
public static bool FlippedVertically(FlipFlags flags) { return((flags & FlipFlags.Vertical) != 0); }
public virtual void SetFrame(Frame value) { _frame = value; _origin.X = _frame.Center.X; _origin.Y = _frame.Center.Y; _flipMode = (FlipFlags)_frame.FlipMode; }
public static bool RotatedHexagonally120(FlipFlags flags) { return((flags & FlipFlags.Hexagonal120) != 0); }
protected virtual void SetFlipMode(FlipFlags flipMode) { _flipMode = flipMode; Frame.FlipMode = (SpriteEffects)flipMode; }
public void BuildSprite(int indexOffset, ref Matrix2 transformMatrix, Texture2D texture, ref Rectangle sourceRectangle, Color?color = null, FlipFlags flags = FlipFlags.None, float depth = 0) { if (texture == null) { throw new ArgumentNullException(nameof(texture)); } var texelLeft = 0f; var texelTop = 0f; var texelRight = 1f; var texelBottom = 1f; if (sourceRectangle.Width > 0) { texelLeft = (float)sourceRectangle.X / texture.Width; texelTop = (float)sourceRectangle.Y / texture.Height; texelRight = (sourceRectangle.X + sourceRectangle.Width) / (float)texture.Width; texelBottom = (sourceRectangle.Y + sourceRectangle.Height) / (float)texture.Height; } else { sourceRectangle.Width = texture.Width; sourceRectangle.Height = texture.Height; } var color1 = color ?? Color.White; var vertices = Vertices; transformMatrix.Transform(0, 0, ref vertices[0].Position); vertices[0].Position.Z = depth; vertices[0].Color = color1; vertices[0].TextureCoordinate.X = texelLeft; vertices[0].TextureCoordinate.Y = texelTop; transformMatrix.Transform(sourceRectangle.Width, 0, ref vertices[1].Position); vertices[1].Position.Z = depth; vertices[1].Color = color1; vertices[1].TextureCoordinate.X = texelRight; vertices[1].TextureCoordinate.Y = texelTop; transformMatrix.Transform(0, sourceRectangle.Height, ref vertices[2].Position); vertices[2].Position.Z = depth; vertices[2].Color = color1; vertices[2].TextureCoordinate.X = texelLeft; vertices[2].TextureCoordinate.Y = texelBottom; transformMatrix.Transform(sourceRectangle.Width, sourceRectangle.Height, ref vertices[3].Position); vertices[3].Position.Z = depth; vertices[3].Color = color1; vertices[3].TextureCoordinate.X = texelRight; vertices[3].TextureCoordinate.Y = texelBottom; var flipDiagonally = (flags & FlipFlags.FlipDiagonally) != 0; var flipHorizontally = (flags & FlipFlags.FlipHorizontally) != 0; var flipVertically = (flags & FlipFlags.FlipVertically) != 0; if (flipDiagonally) { FloatHelper.Swap(ref vertices[1].TextureCoordinate.X, ref vertices[2].TextureCoordinate.X); FloatHelper.Swap(ref vertices[1].TextureCoordinate.Y, ref vertices[2].TextureCoordinate.Y); } if (flipHorizontally) { if (flipDiagonally) { FloatHelper.Swap(ref vertices[0].TextureCoordinate.Y, ref vertices[1].TextureCoordinate.Y); FloatHelper.Swap(ref vertices[2].TextureCoordinate.Y, ref vertices[3].TextureCoordinate.Y); } else { FloatHelper.Swap(ref vertices[0].TextureCoordinate.X, ref vertices[1].TextureCoordinate.X); FloatHelper.Swap(ref vertices[2].TextureCoordinate.X, ref vertices[3].TextureCoordinate.X); } } if (flipVertically) { if (flipDiagonally) { FloatHelper.Swap(ref vertices[0].TextureCoordinate.X, ref vertices[2].TextureCoordinate.X); FloatHelper.Swap(ref vertices[1].TextureCoordinate.X, ref vertices[3].TextureCoordinate.X); } else { FloatHelper.Swap(ref vertices[0].TextureCoordinate.Y, ref vertices[2].TextureCoordinate.Y); FloatHelper.Swap(ref vertices[1].TextureCoordinate.Y, ref vertices[3].TextureCoordinate.Y); } } VertexCount = 4; AddQuadrilateralIndices(indexOffset); IndexCount = 6; PrimitivesCount = 2; }
/// <summary> /// Performs a bit-block-transfer from the source brush to /// the destination brush, applying the specified paletteIndex. /// Any pixels with a value of zero will be rendered transparently. /// </summary> /// <param name="tile">The count of the tile to be used from the source brush</param> /// <param name="destX">The x-coordinate of the tile to be drawn to in the destination</param> /// <param name="destY">The y-coordinate of the tile to be drawn to in the destination</param> /// <param name="pal">The paletteIndex to use.</param> /// <param name="flip">Indicates how the tile should be flipped</param> /// <remarks>The paletteIndex specified will work for the range 0 through 31 if the source /// brush is formatted correctly, but for NES screen rendering typically only the first four /// palettes will be used.</remarks> public void BlitTileTransparentFlipped(int tile, int destX, int destY, byte pal, FlipFlags flip) { switch (flip) { case FlipFlags.Horizontal: BltTransFlipH(tile, destX, destY, pal); break; case FlipFlags.Vertical: BltTransFlipV(tile, destX, destY, pal); break; case (FlipFlags.Horizontal | FlipFlags.Vertical): BltTransFlipHV(tile, destX, destY, pal); break; default: BlitTileTransparent(tile, destX, destY, pal); break; } }