Search code examples
androidandroid-progressbarcocos2d-android

Put image on progressbar in android


I want to superimpose image of different color on my progress bar depending on the progress percentage.

I putted the image on right position and set it invisible initially and setting it visible depending on condition.

Problem is that image is not visible over the progress bar it is visible below the progress bar.

Here is my code for progress bar:

progressbar = CCProgressTimer.progress("TimeBar23.png");
progressbar.setType(5);
progressbar.setAnchorPoint(0, 0);


// progressbar.setPosition(47, 356);
progressbar.setPosition(47, 310);

and here is the images:

progressBarImage1.setPosition(68,500);
progressBarImage2.setPosition(68,456);
progressBarImage3.setPosition(68, 424);

progressBarImage1.setVisible(false);
progressBarImage2.setVisible(false);
progressBarImage3.setVisible(false);

and here is the condition on which I am making my images visible:

if(GamebarLayer.progressbar.getPercentage() > 33.33)
{
    GamebarLayer.progressBarImage1.setVisible(true);
    GamebarLayer.progressBarImage1.setVertexZ(100);
}
else if(GamebarLayer.progressbar.getPercentage() > 66.66)
{
    GamebarLayer.progressBarImage2.setVisible(true);
}
else if(GamebarLayer.progressbar.getPercentage() > 100)
{
    GamebarLayer.progressBarImage3.setVisible(true);
}

Please help me in this.


Solution

  • the image which is used in the progressbar : Try this addChild(progressBar, 1);

    here "1" is gave the priority to the pogressbar on the Layer.