Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Image size dependant on number

    Hey guys,

    So i want to create a HP bar for my character. I want it so, that if the HP of my character is half, then the image for of my HP bar will only fill half way.

    Any ideas on how i would do this?

    Thanks!

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ole90 View Post
    Hey guys,

    So i want to create a HP bar for my character. I want it so, that if the HP of my character is half, then the image for of my HP bar will only fill half way.

    Any ideas on how i would do this?

    Thanks!
    Huh???????

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did this in a little game I played around with.

    PHP Code:
    $percent_health = ($current_hp/$maximum_hp) * 100;

                    echo 
    "<table bgcolor='green' width='100%' cellspacing='0' cellpadding='0' border='0'>";
                    echo 
    "<tr>";
                    echo 
    "<td align='right' width='".$percent_health."%'>";
                            echo 
    "&nbsp;";
                    echo 
    "</td>";
                    echo 
    "<td class='norm'>";
                            echo 
    "&nbsp;".$percent_health."%";
                    echo 
    "</td>";
                    echo 
    "</tr>";
                    echo 
    "</table>"
    something like that

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Okay, maybe i wasn't clear enough.

    You know when you play a game and your have your own character with HP and a HP bar like so:

    HP: 50/100
    [hp bar image]

    Well, i want the hp bar image, in this case, to reach on halfway. So the image is size depnds on the hp you the user has.

  • #5
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this instead of what I posted above if you want it in that layout. It doesn't actually make an image but makes a table instead. The tables width is equal to the percentage of health you have remaining.

    PHP Code:
    echo "HP: ".$current_hp."/".$maximum_hp;
    $percent_health = ($current_hp/$maximum_hp) * 100;

                    echo 
    "<table bgcolor='green' width='100%' cellspacing='0' cellpadding='0' border='0'>";
                    echo 
    "<tr>";
                    echo 
    "<td align='right' width='".$percent_health."%'>";
                            echo 
    "&nbsp;";
                    echo 
    "</td>";
                    echo 
    "</tr>";
                    echo 
    "</table>"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •