Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix health bar stretching instead of clip the texture #228

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/ru/nsu/ccfit/zuev/osu/game/ScoreBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,29 @@ public class ScoreBar extends GameObject {
private final AnimSprite ki;
private final float width;
private float lasthp = 0;
private final float mColourX = Utils.toRes(5);

public ScoreBar(final GameObjectListener listener, final Scene scene,
final StatisticV2 stat) {
this.stat = stat;
bg = new Sprite(0, 0, ResourceManager.getInstance().getTexture(
"scorebar-bg"));
bg.setScaleCenter(0, 0);
/*final int colourFrames = SkinManager.getFrames("scorebar-colour");
colour = new AnimSprite(Utils.toRes(5), Utils.toRes(16),
"scorebar-colour-", colourFrames, colourFrames);*/

if (ResourceManager.getInstance().isTextureLoaded("scorebar-colour-0")) {
List<String> loadedScoreBarTextures = new ArrayList<>();
for (int i = 0; i < 60; i++) {
if (ResourceManager.getInstance().isTextureLoaded("scorebar-colour-" + i))
loadedScoreBarTextures.add("scorebar-colour-" + i);
}
colour = new AnimSprite(Utils.toRes(5), Utils.toRes(16), loadedScoreBarTextures.size(),

colour = new AnimSprite(mColourX, Utils.toRes(16), loadedScoreBarTextures.size(),
loadedScoreBarTextures.toArray(new String[loadedScoreBarTextures.size()]));
} else {
colour = new Sprite(Utils.toRes(5), Utils.toRes(16),
colour = new Sprite(mColourX, Utils.toRes(16),
ResourceManager.getInstance().getTexture("scorebar-colour"));
}
width = colour.getWidth();
/*for (int i = 0; i < colour.getTextureRegionCount(); i++) {
colour.setTextureRegion(i, colour.getTextureRegionAt(i).deepCopy());
}*/
ki = ResourceManager.getInstance().isTextureLoaded("scorebar-kidanger")
? new AnimSprite(0, 0, 0, "scorebar-ki", "scorebar-kidanger", "scorebar-kidanger2")
: new AnimSprite(0, 0, 0, "scorebar-ki");
Expand All @@ -70,27 +67,32 @@ public void update(final float dt) {
hp = speed * dt * Math.signum(hp - lasthp) + lasthp;
}

/*for (int i = 0; i < colour.getTextureRegionCount(); i++) {
colour.getTextureRegionAt(i).setWidth((int) (width * hp));
}*/
colour.setWidth(width * hp);
float translationX = width * (1 - Math.abs(hp));

ki.setPosition(Utils.toRes(5) + colour.getWidth() - ki.getWidth() / 2,
colour.setPosition(mColourX - translationX, colour.getY());

if (colour.getClass() == Sprite.class)
{
colour.getTextureRegion().setTexturePosition((int) -translationX, 0);
}
else if (colour.getClass() == AnimSprite.class)
{
AnimSprite sprite = (AnimSprite) colour;

int i = sprite.getTextureRegionCount() - 1;
while (i >= 0)
{
sprite.getTextureRegionAt(i).setTexturePosition((int) -translationX, 0);
--i;
}
}

ki.setPosition(Utils.toRes(5) + colour.getX() + width - ki.getWidth() / 2,
Utils.toRes(16) + colour.getHeight() / 2 - ki.getHeight() / 2);
//ki.setScale(hp>lasthp?1.2f:1);
ki.setFrame(hp > 0.49 ? 0
: hp > 0.24 ? 1
: 2);
lasthp = hp;
/*if (hp < 0.5f) {
if (hp < 0.25f) {
ki.setFrame(2);
} else {
ki.setFrame(1);
}
} else {
ki.setFrame(0);
}*/
}

public void flush() {
Expand Down