public override void Update(TimeSpan elapsed) { base.Update(elapsed); mSecondsSinceUpdate += (float)elapsed.TotalSeconds; if (mSecondsSinceUpdate >= SecondsPerFrame) { mSecondsSinceUpdate -= SecondsPerFrame; mFlipImage = (mFlipImage == GsImageFlip.None) ? GsImageFlip.Horizontal : GsImageFlip.None; } }
public override void Update(TimeSpan elapsed) { this.UpdateTimeToLive(elapsed); mSecondsSinceUpdate += (float)elapsed.TotalSeconds; if (mSecondsSinceUpdate >= SecondsPerFrame) { mSecondsSinceUpdate -= SecondsPerFrame; effects = (effects == GsImageFlip.None ? GsImageFlip.Horizontal : GsImageFlip.None); } }
public static SpriteEffects ToSpriteEffects(this GsImageFlip flip) { switch (flip) { case GsImageFlip.Both: return(SpriteEffects.FlipBoth); case GsImageFlip.Horizontal: return(SpriteEffects.FlipHorizontally); case GsImageFlip.Vertical: return(SpriteEffects.FlipVertically); } return(SpriteEffects.None); }
public void DrawImage(GsImage image, GsRectangle dest, GsRectangle?source, GsVector origin, float angle, GsImageFlip flip, GsColor tint) { DrawSprite(image.Data as TextureData, dest, source, origin, angle, flip, tint); }
private void DrawSprite(TextureData data, GsRectangle dst, GsRectangle?source, GsVector origin, float rotation, GsImageFlip flip, GsColor color) { if (color.A <= 0) { return; } GsSize texSize = new GsSize(data.Bitmap.Width, data.Bitmap.Height); GsRectangle src = source.GetValueOrDefault( new GsRectangle(GsVector.Zero, texSize)); using (data.Bind()) { GL.Color4(color.R, color.G, color.B, color.A); // Setup the matrix GL.PushMatrix(); if ((dst.X != 0) || (dst.Y != 0)) { GL.Translate(dst.X, dst.Y, 0f); } if (rotation != 0) { GL.Rotate(MathHelper.RadiansToDegrees(rotation), 0, 0, 1); } if ((dst.Width != 0 && origin.X != 0) || (dst.Height != 0 && origin.Y != 0)) { GL.Translate( -origin.X * (float)dst.Width / (float)src.Width, -origin.Y * (float)dst.Height / (float)src.Height, 0f); } // Calculate the points on the texture float x = src.X / texSize.Width; float y = src.Y / texSize.Height; float twidth = src.Width / texSize.Width; float theight = src.Height / texSize.Height; Vector2[] tx = new Vector2[] { new Vector2(x, y + theight), new Vector2(x + twidth, y + theight), new Vector2(x + twidth, y), new Vector2(x, y), }; var tcs = texCoords[flip]; int t = 0; GL.Begin(PrimitiveType.Quads); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(0f, dst.Height); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(dst.Width, dst.Height); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(dst.Width, 0f); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(0f, 0f); GL.End(); GL.PopMatrix(); } }
public void DrawImage(GsImage image, GsRectangle dest, GsRectangle?source, GsVector origin, float angle, GsImageFlip flip, GsColor tint) { SwitchMode(Mode.Sprites); Rectangle?src = null; if (source.HasValue) { var s = source.Value; src = new Rectangle((int)s.X, (int)s.Y, (int)s.Width, (int)s.Height); } var dst = new RectangleF(dest.X, dest.Y, dest.Width, dest.Height); spriteBatch.Draw(image.Data as Texture2D, dst, src, tint.ToColor(), angle, new Vector2(origin.X, origin.Y), flip.ToSpriteEffects(), 0f); }
public static void DrawImage(this IGsGraphics graphics, ImageParams data, GsColor color, GsVector offset, float rotation, GsImageFlip flip) { var size = data.ImageSize.ToVector() * data.Scale; var dest = new GsRectangle(data.Position + offset, size.ToSize()); graphics.DrawImage(data.Image, dest, null, data.Origin, rotation, flip, color); }