简体   繁体   中英

How can I make a sprite to do a visible moving from a position to a mouse click in monogame?

I am making a fireball, which is moving to a mouse clicked position. The fireball sprite is already moving to the postion, but I can't see the fireball fly. I want to see, that the fireball "flys" to the postion?

here is my monogame code, written in c#

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

            // TODO: Add your update logic here
            var CurrentMouseState = Mouse.GetState();
            PreviousMouseState = CurrentMouseState;
            if (CurrentMouseState.LeftButton == ButtonState.Pressed)
            {
                ballPosition = new Vector2(CurrentMouseState.X, CurrentMouseState.Y);

            }

            base.Update(gameTime);
        }

Could anybody help me? I didn't find help in other questions.

So far the ball is moving instantly to the position to the mouse. but now it needs to move on it's own to the mouse position.

Assuming with 'flying towards the mouse', you mean moving in a straight line to the mouse position. You can try using Vector2.Normalize to decide in which direction and angle it needs to move to the mouse.

Try out the answer found here: https://gamedev.stackexchange.com/a/7757/96707

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM