1

私は MonoGame 開発者で、携帯電話の画面に曲線を描きたいと思っていますが、曲線は規則的ではなくぎくしゃくしており、複数の線で構成されています。

私はこのようないくつかのコードを使用しました:

最初の方法は、次のように間隔を空けてスプライトを均等に描画します。

 // increment is how far apart each sprite is drawn
private void DrawEvenlySpacedSprites(Texture2D texture, Vector2 point1, Vector2 point2, float     increment)
{
    var distance = Vector2.Distance(point1, point2);    // the distance between two points
    var iterations = (int)(distance / increment);       // how many sprites with be drawn
    var normalizedIncrement = 1.0f / iterations;        // the Lerp method needs values between 0.0 and 1.0
    var amount = 0.0f;

    if(iterations == 0)
        iterations = 1;

    for (int i = 0; i < iterations; i++)
    {
        var drawPoint = Vector2.Lerp(point1, point2, amount);
        _spriteBatch.Draw(texture, drawPoint, Color.White);
        amount += normalizedIncrement;
    }
}

Update メソッド:

private Vector2? _previousPoint;
protected override void Update(GameTime gameTime)
{
    TouchCollection touches = TouchPanel.GetState();

    foreach (TouchLocation touch in touches)
    {
        if (touch.State == TouchLocationState.Moved)
        {
            GraphicsDevice.SetRenderTarget(renderTarget);
            _spriteBatch.Begin();

            if (_previousPoint.HasValue)
                DrawEvenlySpacedSprites(texture, _previousPoint.Value, touch.Position, 0.5f);

            _spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);
        }
    }

    if (touches.Any())
        _previousPoint = touches.Last().Position;
    else
        _previousPoint = null;

    base.Update(gameTime);
}

私はこの結果を持っています:

ここに画像の説明を入力

それを改善するために、ベジエ曲線を使用しようとしましたが、この解決策を実装できませんでした。

助けてください。

貴重なご意見、ご提案をお待ちしております。

4

0 に答える 0