Reputation: 13
I'm trying to program a "Health Bar" using libGDX's progress bar and I've created (and used code i found online) some code that basically did what I need it to and implemented it into my program. This worked completely okay by itself in a separate empty libGDX program
Originally the getColoredDrawable
method was in a separate class, i've also tried removing the Static
context
However neither of these fixed things, and it needs to be in a static context for getStyle
method to operate.
This is the code I have right now
public HealthBar(int max, int width, int height) {
super(0f, max, 0.01f, false, new ProgressBarStyle());
getStyle().background = getColoredDrawable(width, height, Color.RED);
getStyle().knob = getColoredDrawable(0, height, Color.GREEN);
getStyle().knobBefore = getColoredDrawable(width, height, Color.GREEN);
setWidth(width);
setHeight(height);
setAnimateDuration(0.0f);
setValue(1f);
setAnimateDuration(0.25f);
}
public static Drawable getColoredDrawable(int width, int height, Color color) {
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
pixmap.fill();
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture(pixmap)));
pixmap.dispose();
return drawable;
}
}
This causes an this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'java.nio.ByteBuffer com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.newPixmap(long[], int, int, int)'
I'm sure it has something to do with referencing Pixmap from a static context, however I know it works, because if i write this code into it's own project it works fine. So I'm a bit lost.
I know it could also be that I have setup the project incorrectly and the project be unable to access Gdx2DPixmap but if that is the case I'm not sure how that's occurred
Full Exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'java.nio.ByteBuffer com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.newPixmap(long\[\], int, int, int)'
at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.newPixmap(Native Method)
at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.\<init\>(Gdx2DPixmap.java:137)
at com.badlogic.gdx.graphics.Pixmap.\<init\>(Pixmap.java:137)
at com.mygdx.game.Tools.HealthBar.getColoredDrawable(HealthBar.java:41)
at com.mygdx.game.Tools.HealthBar.\<init\>(HealthBar.java:27)
at com.mygdx.game.Entity.Entity.setupHealthBar(Entity.java:46)
at com.mygdx.game.Entity.Entity.\<init\>(Entity.java:41)
at com.mygdx.game.GameLoop.\<init\>(GameLoop.java:19)
at com.mygdx.game.DesktopLauncher.main(DesktopLauncher.java:23)
All Code Referencing HealthBar
HealthBar.java:41-27
public HealthBar(int max, int width, int height) {
super(0f, max, 0.01f, false, new ProgressBarStyle());
getStyle().background = getColoredDrawable(width, height, Color.RED);
getStyle().knob = getColoredDrawable(0, height, Color.GREEN);
getStyle().knobBefore = getColoredDrawable(width, height, Color.GREEN);
setWidth(width);
setHeight(height);
setAnimateDuration(0.0f);
setValue(1f);
setAnimateDuration(0.25f);
}
public static Drawable getColoredDrawable(int width, int height, Color color) {
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
pixmap.fill();
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture(pixmap)));
pixmap.dispose();
return drawable;
}
}
Entity.java:46
private void setupHealthBar(){healthBar = new HealthBar(this.mHP, 100, 10);healthBar.setPosition(this.x + (float) this.imgSize.width /2, this.y + this.imgSize.height + 20);}
Upvotes: 0
Views: 56