@Yorb_Yorbi wrote:
Hello,
I was trying to implement a HeathBar. I need two heathbars for two characters, and for 1st bar when I cut the health texture from Right to Left everything is working fine. But now I need to do the opposite, I need to cut a texture from Left to Right (image).
And I don't know how to do it properly.
It's my method where I calculate % of texture according to the current HP and then I set the sourceRectangle.
As I said for the right bar method is cutting from right to left and I don't know how to change it.` public void Draw(SpriteBatch spriteBatch, double hp, bool isMonster, Vector2 cameraPos)
{
double healthIntoTexture = (hp * fullHealthInPixels) / (double)MaxHp;rectanglHealthLeft = new Rectangle(0, 0, (int)healthIntoTexture, healthTextureLeft.Height); rectanglHealthRight = new Rectangle(0, 0, (int)healthIntoTexture, healthTextureRight.Height); // ??????? rectangleForBar = new Rectangle(0, 0, barTextureLeft.Width, barTextureLeft.Height); var originLeft = new Vector2(rectanglHealthLeft.Left, rectanglHealthLeft.Top); var originRight = new Vector2(rectanglHealthRight.Left, rectanglHealthRight.Top); var originBar = new Vector2(rectangleForBar.Left, rectangleForBar.Top); if (isMonster) { spriteBatch.Draw(barTextureLeft, new Vector2(cameraPos.X + 200 - 3, cameraPos.Y + 50 - 4), rectangleForBar, Color.White, 0.0f, originBar, 0.5f, SpriteEffects.None, 0.0f); spriteBatch.Draw(healthTextureLeft, new Vector2(cameraPos.X + 200, cameraPos.Y + 50), rectanglHealthLeft, Color.White, 0.0f, originLeft, 0.5f, SpriteEffects.None, 0.0f); } else { spriteBatch.Draw(barTextureRight, new Vector2(cameraPos.X + 1000 - 8, cameraPos.Y + 50 - 4), rectangleForBar, Color.White, 0.0f, originBar, 0.5f, SpriteEffects.None, 0.0f); spriteBatch.Draw(healthTextureRight, new Vector2(cameraPos.X + 1000, cameraPos.Y + 50), rectanglHealthRight, Color.White, 0.0f, originRight, 0.5f, SpriteEffects.None, 0.0f); // ??? } }`
Posts: 2
Participants: 1