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' />

 

Link to comment
Share on other sites

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" /> ';
}

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.