Jump to content

Repeat Image Depending On Variable?


Rdogg112

Recommended Posts

umm, im making a game and characters HP so far is just text how would i make an image of about 1px X 5px show if the hp is 50 it would show 50 times like this:

 

HP 50/100

bar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.pngbar_green.png

 

could anyone help me?

<?php $hp=$_GET["hp"]; ?>

<img src='line.jpg' width='<?php echo $hp; ?>' height='5px' />

 

If it's 1 pixel large, stretching it is the best option. If, let's say you have hearts (like in Zelda), then you would need to repeat it using a simple for loop:

 

<?php
$lives = 4;

for ( $i = 0; $i < $lives; $i++ ) {
    echo '<img src="/images/heart.png" alt="<3" /> ';
}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.