Fixed positiondraw on client

This commit is contained in:
SergoDobro 2024-08-20 15:07:05 +03:00
parent 2af8b374ac
commit e88b697b2c
3 changed files with 13 additions and 7 deletions

View file

@ -41,12 +41,12 @@ public class LivingEntity : Entity
Vector2 prevPosition_forClient;
public override void Draw(SpriteBatch spriteBatch)
{
if ((position - prevPosition_forClient).X < 0)
if ((positionDraw - prevPosition_forClient).X < 0)
graphicsComponent.Flip = SpriteEffects.FlipHorizontally;
else if ((position - prevPosition_forClient).X > 0)
else if ((positionDraw - prevPosition_forClient).X > 0)
graphicsComponent.Flip = SpriteEffects.None;
base.Draw(spriteBatch);
prevPosition_forClient = position;
prevPosition_forClient = positionDraw;
}
public virtual void Die()

View file

@ -46,8 +46,8 @@ public class Player : LivingEntity
lootData = new LootData();
lootData.loots = new Dictionary<string, int>();
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 15, 30, 15);
speed = 2.5f;
collisionComponent.stopRectangle = new Rectangle(10, 15, 10, 15);
speed = 5;
StartAnimation("player_look_down");
}

View file

@ -58,6 +58,7 @@ public abstract class GameObject
public void PlayAnimation_OnClient()
{
graphicsComponent.Update();
}
/// <summary>
@ -69,14 +70,19 @@ public abstract class GameObject
graphicsComponent.LoadContent();
}
/// <summary>
/// for smooth client draw
/// </summary>
public Vector2 positionDraw;
/// <summary>
/// Для клиента
/// Обновление, которое вызывается у клиента, для просмотра анимаций
/// </summary>
public virtual void UpdateAnimations()
{
graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
positionDraw = (position * 0.15f + positionDraw*0.85f);
graphicsComponent.ObjectDrawRectangle.X = (int)positionDraw.X; //Move To place where Updates Sets your position
graphicsComponent.ObjectDrawRectangle.Y = (int)positionDraw.Y;
PlayAnimation_OnClient();
}