question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help! My NinePatch ProgressBar background is not appearing when the slice values are set

See original GitHub issue

I need help! What am I doing wrong? When I remove the 4 integer slice values, the background is displayed (of course, stretched very weirdly). However, when I put in the 4 slice values, the NinePatch doesn’t display at all.

progressBar, progressBarStyle and background are defined elsewhere in the class.

add(progressBar=new ProgressBar(
	0f,
	100f,
	0.1f,
	false,
	progressBarStyle=new ProgressBar.ProgressBarStyle(
		background=new NinePatchDrawable(new NinePatch(
			TextureRegionFinder.findTextureRegion(
				arena.tuxFight.assetManager,
				"barbackground.png"
			),
			11,
			11,
			11,
			11
		)),
		null
	)
));
progressBar.setRound(false);
progressBar.setBounds(0,0,width,height);
progressBar.setValue(MathUtils.clamp(value,0f,100f));
progressBar.setAnimateDuration(1f);
background.setMinSize(width,height);
background.tint(endColor);

progressBarStyle.knobBefore=new BaseDrawable(){
	{
		setMinHeight(progressBar.getHeight());
	}
	ShapeRenderer shapeRenderer=new ShapeRenderer();
	@Override
	public void draw(Batch batch,float x,float y,float width,float height){
		batch.end();
		shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
		shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
		shapeRenderer.rect(x+7f,y+7f,(width-14f)*0.25f,height-14f,zeroColor,midColor,midColor,zeroColor);
		shapeRenderer.rect(x+7f+(width-14f)*0.25f,y+7f,(width-14f)*0.75f,height-14f,midColor,endColor,endColor,midColor);
		shapeRenderer.end();
		batch.begin();
	}
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tommyettingercommented, Jul 11, 2021

Please use the Discord for help requests; the #scene2d, #help-1 or #help-2 topics would all be appropriate avenues. If you don’t have Discord, the libGDX server link is here. This doesn’t look like a bug or other issue in libGDX, but I’m not comfortable enough with 9patches to say that with confidence, so I’ll leave this open for now.

As an aside, you may want ShapeDrawer rather than ShapeRenderer, to avoid frequently ending and beginning the batch.

0reactions
customautosyscommented, Jul 25, 2021

Hi, I found out the problem. The NinePatch simply doesn’t work when the TextureRegion is flipped (vertically).

See https://github.com/siauderman/NinePatchTest

I believe this is a bug. Surely NinePatches should work even when the TextureRegion is flipped.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using 'small' values in progressBar with 9 patch looks bad
1 Answer 1 ... You are setting your NinePatch width to be less than the minimum. The left and right do not change,...
Read more >
ProgressBar - Android Developers
Display progress bars to a user in a non-interruptive way. Show the progress bar in your app's user interface or in a notification...
Read more >
9-slicing Sprites - Unity - Manual
This page describes how to set 9-slicing up, and which settings to apply depending on whether you want to stretch or tile the...
Read more >
NinePatchRect - Godot Docs
Scalable texture-based frame that tiles the texture's centers and sides, but keeps the corners' original size. Perfect for panels and dialog boxes.
Read more >
progressBar command
Each component ranges in value from 0.0 to 1.0. When setting backgroundColor, the background is automatically enabled, unless enableBackground is also specified ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found