Skip to content

Commit

Permalink
Added bar.SetLerpFull() to cover a lerp from start to end
Browse files Browse the repository at this point in the history
  • Loading branch information
RhenaudTheLukark committed Jul 29, 2023
1 parent 036f407 commit d79940c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Battle/FightUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void Update() {
int newHP = enemy.HP - Damage;
lifeBar.outline.img.transform.localPosition = new Vector2(enemy.offsets[2].x - 1, -eneSize.y / 2 + 20 + enemy.offsets[2].y - 1);
lifeBar.Resize(enemy.GetComponent<RectTransform>().rect.width, 13);
lifeBar.SetLerp(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP);
lifeBar.SetLerpFull(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP);
lifeBar.SetVisible(true);
enemy.doDamage(Damage);
}
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Battle/LifeBarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void SetInstant(float fillValue, bool allowNonClamped = false) {
/// <param name="fillValue">Value the healthbar should be at when finished, in range of [0.0, 1.0].</param>
/// <param name="time">Time for the healthbar to reach its destination in frames.</param>
/// <param name="allowNonClamped">True if values outside of the range [0.0, 1.0] should be kept.</param>
public void SetLerp(float originalValue, float fillValue, int time, bool allowNonClamped = false) {
public void SetLerpFull(float originalValue, float fillValue, int time = 60, bool allowNonClamped = false) {
fillLinearTime = time / 60f;

if (!allowNonClamped) {
Expand All @@ -137,13 +137,13 @@ public void SetLerp(float originalValue, float fillValue, int time, bool allowNo
}

/// <summary>
/// Start a linear-time transition from first value to second value.
/// Start a linear-time transition from the current value to a given value.
/// </summary>
/// <param name="originalValue">Value to start the healthbar at, in range of [0.0, 1.0].</param>
/// <param name="fillValue">Value the healthbar should be at when finished, in range of [0.0, 1.0].</param>
/// <param name="time">Time for the healthbar to reach its destination in frames.</param>
/// <param name="allowNonClamped">True if values outside of the range [0.0, 1.0] should be kept.</param>
public void SetLerp(float originalValue, float fillValue, bool allowNonClamped = false) {
SetLerp(originalValue, fillValue, 60, allowNonClamped);
public void SetLerp(float fillValue, int time = 60, bool allowNonClamped = false) {
SetLerpFull(desiredFill, fillValue, time, allowNonClamped);
}

/// <summary>
Expand Down
11 changes: 10 additions & 1 deletion Documentation CYF 1.0/pages/api-functions-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,16 @@ <h3><span class="CYF"></span> The Bar Object [E/M/W]</h2><br><br>
</p>

<p>
<br><span class="function"> Bar.SetLerp(<span class="number"></span> originalValue, <span class="number"></span> fillValue, <span class="number"></span> time = 60, <span class="boolean"></span> allowNonClamped = false)</span>
<br><span class="new function"> Bar.SetLerp(<span class="number"></span> fillValue, <span class="number"></span> time = 60, <span class="boolean"></span> allowNonClamped = false)</span>
Gradually sets the fill percentage of the bar object between 0 and 1 from the bar's current fill to <span class="term">fillValue</span> over <span class="term">time</span> frames, with 60 frames being equal to one second. <span class="term">0</span> means the bar is empty, while <span class="term">1</span> means it is full.
<br><br>
If <span class="term">allowNonClamped</span> is set to true, you can use values lower than 0 and higher than 1.
<br><br>
Note that the bar will be updated properly when <span class="term">fillValue</span> is beyond its usual bounds only if the <span class="term">bar-px</span> sprite is used for all of the bar's sprites.
</p>

<p>
<br><span class="new function"> Bar.SetLerpFull(<span class="number"></span> originalValue, <span class="number"></span> fillValue, <span class="number"></span> time = 60, <span class="boolean"></span> allowNonClamped = false)</span>
Gradually sets the fill percentage of the bar object between 0 and 1 from <span class="term">originalValue</span> to <span class="term">fillValue</span> over <span class="term">time</span> frames, with 60 frames being equal to one second. <span class="term">0</span> means the bar is empty, while <span class="term">1</span> means it is full.
<br><br>
If <span class="term">allowNonClamped</span> is set to true, you can use values lower than 0 and higher than 1.
Expand Down

0 comments on commit d79940c

Please sign in to comment.