/// <summary> /// Draws the <see cref="SkeletonBodyItem"/>. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="position">Position to draw at.</param> /// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param> /// <param name="color">The color.</param> /// <param name="effect">SpriteEffects to use when drawing.</param> internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect) { // Validate if (Source == null) { return; } // Find the effect Vector2 m; switch (effect) { case SpriteEffects.FlipHorizontally: m = new Vector2(-1, 1); break; case SpriteEffects.FlipVertically: m = new Vector2(1, -1); break; default: m = new Vector2(1, 1); break; } // Calculate the angle float angle; if (Dest == null) { angle = 0.0f; } else { angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2; } // Draw var v = Source.Position + ItemInfo.Offset; Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale); }
/// <summary> /// Draws the <see cref="ICharacterSprite"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param> /// <param name="position">The position to draw the sprite.</param> /// <param name="heading">The character's heading.</param> /// <param name="color">The color of the sprite.</param> public void Draw(ISpriteBatch spriteBatch, Vector2 position, Direction heading, Color color) { // If we have a body modifier being used, invalidate it if: // 1. The heading has changed. // 2. The animation has ended. // // If we don't have a body modifier being used, just ensure we have the correct Set being used. // // If we are moving, always use the walking animation. _currentHeading = heading; // If the body modifier is set, check if it needs to be unset if (_currentBodyModifier != null) { if (_grh.AnimType == AnimType.None || _bodyModifierDirection != heading) { _currentBodyModifier = null; } } // If we are moving, the body modifier is not set, or the sprite is invalid, use the non-modifier set if (Character.Velocity != Vector2.Zero || _currentBodyModifier == null || _grh.GrhData == null) { var prefix = (Character.Velocity == Vector2.Zero ? string.Empty : "Walk "); var directionSuffix = GetDirectionSetName(heading); _currentBodyModifier = null; InternalSetSet(prefix + directionSuffix); } // Ensure the sprite is valid before trying to update and draw it if (_grh.GrhData == null) { return; } // Update and draw the sprite _grh.Update(_currentTime); _grh.Draw(spriteBatch, position, color); }
/// <summary> /// When overridden in the derived class, draws the graphics to the control. /// </summary> /// <param name="currentTime">The current time.</param> protected override void HandleDraw(TickCount currentTime) { if (DesignMode) { base.HandleDraw(currentTime); return; } TransBoxManager.Update(currentTime); RenderWindow.Clear(Color.Black); // Update the cursor display for the transformation box. Only change the cursor if we are currently // under a transbox, or we have just stopped being under one. If we update it every frame, it screws with the // UI display for everything else (like when the cursor is over a textbox). var transBoxCursor = TransBoxManager.CurrentCursor; if (transBoxCursor == null) { if (_wasUnderTransBox) { Cursor = Cursors.Default; _wasUnderTransBox = false; } } else { Cursor = transBoxCursor; _wasUnderTransBox = true; } // TODO: Implement drawing logic // Do some actual work here _spriteBatch.Begin(BlendMode.Alpha, _camera); if (TilesetConfiguration != null) { int x = 0; int y = 0; for (int i = 0; i < TilesetConfiguration.GrhDatas.Count; i++) { var grh = TilesetConfiguration.GrhDatas[i]; Grh nGrh = new Grh(grh); nGrh.Draw(_spriteBatch, new Vector2(y * EditorSettings.Default.GridSize.X, x * EditorSettings.Default.GridSize.Y)); y++; if (y % TilesetConfiguration.Width == 0) { x++; y = 0; } } // Draw little selection box RenderRectangle.Draw(_spriteBatch, new Rectangle(grhX, grhY, EditorSettings.Default.GridSize.X, EditorSettings.Default.GridSize.Y), Color.TransparentWhite, Color.White, -3f); } _spriteBatch.End(); int deltaTime; if (_lastUpdateTime == TickCount.MinValue) deltaTime = 30; else deltaTime = Math.Max(5, (int)(currentTime - _lastUpdateTime)); _lastUpdateTime = currentTime; _camera.Min += _cameraVelocity * (deltaTime / 1000f); }
/// <summary> /// Handles the actual drawing of the <see cref="MapGrh"/>. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> the object can use to draw itself with.</param> protected virtual void HandleDrawing(ISpriteBatch sb) { _grh.Draw(sb, Position, Color, SpriteEffects, Rotation, Origin, Scale); }