Web Analytics Made Easy -
StatCounter PHP to decide out come image - CodingForum

Announcement

Collapse
No announcement yet.

PHP to decide out come image

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP to decide out come image

    Good evening guys, hope all are well!


    I'm in the middle of creating a battle/kill system.

    Whats the best way for me too display a image based on your characters stats? (Gun / Protection / Armour) ect

    (Gun / Protection / Armour) are stored in the DB as a single number depending what level item you have.

    So if I was too create a script that pulls your levels/stats from the DB and then displays the image that suits your numbers? Would that be the best way?

    image.php?stats=1-2-3

  • #2
    Using PHP to display the image itself using get data introduces unnecessary overhead. I would HIGHLY advise against that. Instead there are two approaches you could use...

    1) easy-peasy... just change the image URL on page_load.

    <img src="images/stats_1_2_2.jpg" alt="text describing the current stats">

    Just change which one you're echoing out in realtime.

    Code:
    echo '
      <img
        src="images/stats_', $gun, '_', $protection, '_', $armor, '.jpg"
        alt="Statistics -- Gun : ', $gun, ' Protection:', $protection, ' Armor:', $armor, '"
      >';
    2) The incorrectly named "CSS Sprites" -- put all the images in a single file, then set it as a background to slide it around. This lets you pre-cache ALL the images as a single file, removing any extra load time when the image changes, and reduces the number of handshakes to one -- at the penalty of having to load a single larger image file the first time the page is displayed. I would lean towards this approach just as if this is a game, having the image take time to load on sub-pages can look unprofessional.

    Though really that would hinge on how big each sub-image actually is and how many possibilities there are total.
    Walk the dark path, sleep with angels, call the past for help.
    https://cutcodedown.com
    https://medium.com/@deathshadow

    Comment


    • #3
      I'll go with the first option as this image is loaded on the logged in home screen, a page that isn't really used once logged in.

      Thanks for your help.

      Comment

      Working...
      X