Help with displaying experience inside experience bar bounds

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Help with displaying experience inside experience bar bounds

Post by thetaf »

Heyy :D

Im trying to display the experience of my bubble hero but im having some trouble when i attempt to render it inside
the experience bar's rectangle and i desperately need some help :oops: ..

This is my non working code that doesn't fill the whole rectangle :

Code: Select all

 
int Init3dBubbleStats(Bubble3D& bubble)
{
    bubble.ExperienceForThisLvl = 1000; //Test for 100% fill
    bubble.ExperienceNeededForThisLvl = 1000;
    return 1;
}
 
int GetExperience(int Points,int MaxPoints,int Ratio)
{
    return Points * Ratio / MaxPoints;
}
 
int DisplayExperience()
{
    //Display based on %
    int Show = GetExperience(Bubble.ExperienceForThisLvl,Bubble.ExperienceNeededForThisLvl,ExpBar.Width);
 
    //background
    ShowRect(RED_RECT,ExpBar.x,ExpBar.y,ExpBar.Width,ExpBar.Height);
 
    //foreground
    ShowRect(GREEN_RECT,ExpBar.x,ExpBar.y,Show,ExpBar.Height);
 
    return 1;
}
 
..And im wondering what did i do wrong :|
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Help with displaying experience inside experience bar bo

Post by thetaf »

Did i posted my question in the wrong forum ?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Help with displaying experience inside experience bar bo

Post by serengeor »

The forum is right.
I've looked at your post before but I couldn't really find anything wrong in the code provided.
What does ShowRect contain?
Working on game: Marrbles (Currently stopped).
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Help with displaying experience inside experience bar bo

Post by thetaf »

ShowRect is calling draw2d function and works(the red bar is filled properly).
I think that the problem is that i need to stretch the width so that it fills all the surface of the bar but i don't know how to calculate the ratio per % :(

Code: Select all

 
int Ratio = ?
int Show = Experience * 100/ExperienceMax * Ratio
 
 
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Help with displaying experience inside experience bar bo

Post by serengeor »

the first way looks correct.
Lets say width is 120.
So if you have 100 epx out of 1000 it would get calculated:
100*120/1000=12.
Try printing out every value and looking at other functions for problems.
Working on game: Marrbles (Currently stopped).
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Help with displaying experience inside experience bar bo

Post by thetaf »

serengeor wrote:the first way looks correct.
Lets say width is 120.
So if you have 100 epx out of 1000 it would get calculated:
100*120/1000=12.
Try printing out every value and looking at other functions for problems.
Thank you i think it works now.I replaced all ints with doubles :)
Post Reply