+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP Pets

  1. #1
    scipets2 is offline x10Hosting Member scipets2 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    28

    Wink PHP Pets

    Hi, it's me again. I was wondering if there was a way to make my virtual pets practically any colour from a huge list. and for them to be able to choose accessories from a shop which all gets stored on the database.

    anyway, all the script I need is a colour pallet. to send the colours to the database and code to display the pet in it's chosen colour with accessories in predefined places (eg. ear, head, footware etc.) Im sorry if this isn't too clear I will add more information if necessarily.

  2. #2
    misson is offline Community Advocate misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,391

    Re: PHP Pets

    What you want for an image picker view isn't entirely clear, but here's some stuff to get you started:
    1. There are plenty of color picker widgets for web pages
    2. Simply store the hex value in the table for the user's pet's stats
    3. To color the pet, you can use the GD extension, specifically the imagecolorset (to replace a single color in an indexed, non-shaded, cartoony image) or imagefilter (for true color or shaded images) functions. Use imagecopy to add one image to another, possibly after rotating it. You'll probably need to store the position and orientation of various body parts for each pet as an anchor point and rotation angle for the various accessories. The attachment point for each accessory will also probably need to be stored. When an accessory is drawn on a pet, rotate the accessory around the attachment point and match up the anchor point to the attachment point.
    You could generate an image every time it's requested, or you could cache recent images to reduce server load.

    Google will turn up plenty of information on using GD, including on using imagefilter function with the IMG_FILTER_COLORIZE filter.
    Last edited by misson; 02-26-2010 at 04:00 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    scipets2 is offline x10Hosting Member scipets2 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    28

    Re: PHP Pets

    Thanks, I was hoping I would have a code example however I could try. I've never used GD before
    Last edited by scipets2; 02-27-2010 at 05:14 AM.

  4. #4
    scipets2 is offline x10Hosting Member scipets2 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    28

    Re: PHP Pets

    Ok, I've made the code, however it doesn't seem to be working
    PHP Code:
    <?php
    $im 
    imagecreatefrompng("Dragon.png");

    // Get the color index for the Dragon
    $bg imagecolorat($im6463);
    $r $_GET['r'];
    $g $_GET['g'];
    $b $_GET['b'];
    // Set the fur colour to the database colour
    imagecolorset($im$bg$r$g$b);

    // Output the image to the browser
    header('Content-type: image/png');

    imagepng($im);
    imagedestroy($im);
    ?>
    That's what I've done so far however all I have is a black instead of transparent background, the pet colour doesn't change and If your thinking I've got the coordinates wrong. I haven't because no colours change. Any help?
    Last edited by scipets2; 02-28-2010 at 04:37 AM.

+ Reply to Thread

Similar Threads

  1. Virtual Pets Free Premium Membership
    By amit142 in forum Ads & Offers
    Replies: 1
    Last Post: 11-17-2008, 07:13 AM
  2. Virtual Pets online game
    By amit142 in forum Gamer's Lounge
    Replies: 1
    Last Post: 11-16-2008, 03:09 PM
  3. post your pets winner get 1k credits
    By sk8er in forum The Marketplace
    Replies: 27
    Last Post: 12-05-2007, 11:55 PM
  4. Pets?
    By Cynical in forum Off Topic
    Replies: 9
    Last Post: 06-01-2006, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers