开始时,球在平面物体上滚动,然后,它在倾斜的物体上滚动。在平面物体上,球的阴影被绘制在正确的位置,但是在倾斜的物体上,球的阴影始终位于错误的位置。阴影应始终位于球的中间位置。
当球在地面上(扁平物体)时,ShadowRotation = 0f。 当球在障碍物(倾斜物体)上时,ShadowRotation = -0.24f,因为障碍物的上升是-0.24f。 变量ShadowRotation是球在倾斜物体上时唯一变化的变量。
当球滚过一个倾斜的物体时,为什么阴影不在正确的位置?谁能解释一下我做错了什么?
Texture2D ShadowSprite, BallSprite, GroundSprite, ObstacleSprite;
float ShadowRotation;
spriteBatch.Draw(GroundSprite, new Vector2(GroundPosition.X, GroundPosition.Y), null, Color.White, 0, new Vector2(GroundSprite.Width / 2.0f, GroundSprite.Height / 2.0f), 1f, SpriteEffects.None, 0.10f);
spriteBatch.Draw(ObstacleSprite, new Vector2(ObstaclePosition.X, ObstaclePosition.Y), null, Color.White, 0, new Vector2(ObstacleSprite.Width / 2.0f, ObstacleSprite.Height / 2.0f), 1f, SpriteEffects.None, 0.09f);
spriteBatch.Draw(ShadowSprite, new Vector2(BallPosition.X, BallPosition.Y + BallSprite.Height / 2.0f), null, Color.White, ShadowRotation, new Vector2(ShadowSprite.Width / 2.0f, ShadowSprite.Height / 2.0f), 1f, SpriteEffects.None, 0.08f);
spriteBatch.Draw(BallSprite, new Vector2(BallPosition.X, BallPosition.Y), null, Color.White, BallRotation, new Vector2(BallSprite.Width / 2.0f, BallSprite.Height / 2.0f), 1f, SpriteEffects.None, 0.07f);