C# 在曲线上移动矩形

C# 在曲线上移动矩形,c#,xna,C#,Xna,当我使用Vector2将纹理移动到特定曲线时,效果很好,但当我使用矩形位置将纹理移动到特定曲线时,纹理不会移动。请帮助,我使用矩形而不是矢量2,这样我可以检测碰撞。您正在使用此绘图重载: destinationRectangle在屏幕坐标中指定绘制精灵的目标 public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch;

当我使用Vector2将纹理移动到特定曲线时,效果很好,但当我使用矩形位置将纹理移动到特定曲线时,纹理不会移动。请帮助,我使用矩形而不是矢量2,这样我可以检测碰撞。

您正在使用此绘图重载:

destinationRectangle在屏幕坐标中指定绘制精灵的目标

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Vector2 initialpos = new Vector2(0,400);
    Vector2 initialvel = new Vector2(100,-50);
    Vector2 acc = new Vector2(0,100f);
    Texture2D image1,wall,wall2;
    float time = 0;
    Vector2 pos,wallpos,wall2pos;
    Rectangle posrec,wallrec;
    KeyboardState keystat;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";            
    }

    protected override void Initialize()
    {
        pos = new Vector2(40,90);
        wallpos = new Vector2(480,350);
        wall2pos = new Vector2(200, 200);
        posrec = new Rectangle(40,90,20,20);
        wallrec = new Rectangle(480,350,20,80);
        base.Initialize();
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        image1 = Content.Load<Texture2D>("Sprites/sprite");
        wall2 = Content.Load<Texture2D>("Sprites/wall2");
        wall = Content.Load<Texture2D>("Sprites/wall");
    }

    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            this.Exit();

        keystat = Keyboard.GetState();

        time += (float)gameTime.ElapsedGameTime.TotalSeconds;
        pos = initialpos + initialvel * time + 0.10f * acc * time * time;
        if(posrec.Intersects(wallrec))
            spriteBatch.Draw(wall2,wall2pos,Color.White);
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();
        spriteBatch.Draw(wall, wallpos, wallrec, Color.White);
        spriteBatch.Draw(image1, pos, posrec, Color.White);
        spriteBatch.End();
        base.Draw(gameTime);
    }
}
public void Draw (
     Texture2D texture,
     Vector2 position,
     Nullable<Rectangle> sourceRectangle,
     Color color
)
public void Draw (
     Texture2D texture,
     Rectangle destinationRectangle,
     Color color
)