Game Development Your number one stop for anything related to creating games (except ROM hacks). You can even make your own!

Reply
 
Thread Tools
  #1    
Old July 31st, 2013 (11:44 AM).
jcl's Avatar
jcl jcl is offline
     
    Join Date: Jul 2013
    Gender: Female
    Posts: 40
    I'm making a dress-up game where you have the option to use a hue, brightness and saturation slider to change the color of your character's hair and clothes.

    I recently learned how to make Actionscript 3 Classes and decided to use one for my game. Here is what my code looks like so far:

    Code:
    package
    {
        import flash.display.MovieClip;
        import fl.events.SliderEvent;
        import flash.geom.ColorTransform;
        import fl.motion.AdjustColor;
        import flash.filters.ColorMatrixFilter;
    
        public class Main extends MovieClip
        {
            private var colorTransform:ColorTransform=new ColorTransform();
            private var color:AdjustColor=new AdjustColor();
            private var filter:ColorMatrixFilter;
            private var hairRoot=MovieClip(root).maleBodyHairFront;
    
            public final function Main():void
            {
                color.brightness=0;
                color.contrast=0;
                color.hue=0;
                color.saturation=0;
                addListeners();
            }
            private final function addListeners():void
            {
                hairWindow1.brightSlider.addEventListener(SliderEvent.CHANGE, updateBrightness);
                hairWindow1.hueSlider.addEventListener(SliderEvent.CHANGE, updateHue);
                hairWindow1.satSlider.addEventListener(SliderEvent.CHANGE, updateSaturation);
            }
            private final function updateBrightness(e:SliderEvent):void
            {
                color.brightness=e.target.value;
                update();
            }
    
        private final function updateHue(e:SliderEvent):void
        {
            color.hue=e.target.value;
            update();
        }
    
        private final function updateSaturation(e:SliderEvent):void
        {
            color.saturation=e.target.value;
            update();
        }
        private function update():void
        {
            filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
            switch(hairRoot.currentFrame)
    {
        case 1:hairRoot.maleBodyHairFrontColor1.filters = [filter];break;
        case 2:hairRoot.maleBodyHairFrontColor2.filters = [filter];break;
        case 3:hairRoot.maleBodyHairFrontColor3.filters = [filter];break;
        case 4:hairRoot.maleBodyHairFrontColor4.filters = [filter];break;
        case 5:hairRoot.maleBodyHairFrontColor5.filters = [filter];break;
        case 6:hairRoot.maleBodyHairFrontColor6.filters = [filter];break;
        case 7:hairRoot.maleBodyHairFrontColor7.filters = [filter];break;
        case 8:hairRoot.maleBodyHairFrontColor8.filters = [filter];break;
        case 9:hairRoot.maleBodyHairFrontColor9.filters = [filter];break;
        case 10:hairRoot.maleBodyHairFrontColor10.filters = [filter];break;
        case 11:hairRoot.maleBodyHairFrontColor11.filters = [filter];break;
        case 12:hairRoot.maleBodyHairFrontColor12.filters = [filter];break;
        case 13:hairRoot.maleBodyHairFrontColor13.filters = [filter];break;
        case 14:hairRoot.maleBodyHairFrontColor14.filters = [filter];break;
        case 15:hairRoot.maleBodyHairFrontColor15.filters = [filter];break;
        case 16:hairRoot.maleBodyHairFrontColor16.filters = [filter];break;
    }
        }
    }
    If you want to get a better picture of what I'm doing, follow a link to the beta version of my game: http://joy-ling.site88.net/trainercreator2.html

    Basically, the sliders are in the second frame of the Movie Clip hairWindow1. I want to be able to change the color of the Movie Clip maleBodyHairFront, which is on the main timeline. maleBodyHairFront has multiple frames inside it, which are all labelled. I also have multiple layers in maleBodyHairFront. One layer is for the outline, another is for the color of the hair (which are movie clips), another is for the colors of the hats (also movieclips), etc. When I test the scene, no errors occur, however, I am unable to change the color of the hair. The rest of my code is inside the timeline.

    What is wrong and how can I fix my problem?
    Reply With Quote

    Relevant Advertising!

      #2    
    Old July 31st, 2013 (12:56 PM).
    th3shark's Avatar
    th3shark th3shark is offline
    Develops in AS3/C++
       
      Join Date: Jul 2013
      Location: Connecticut
      Gender: Male
      Nature: Calm
      Posts: 79
      First of all, this looks very nice! I wish I was as good at vector art as you.

      I'm actually having a hard time finding instances where changing hair color doesn't work. For example, the style on the bottom right of the second page of the front hair lets me change the hat color, but not the hair color. Perhaps you forgot to put a label in a frame of that MovieClip?

      But that seems like a relatively minor issue. Can you be more descriptive in what's wrong?

      Also for nicer code, change update() to this:

      private function update():void {
      filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
      for (var i:int=1;i<=16;i++){
      hairRoot["maleBodyHairFrontColor"+String(i)].filters = [filter];
      //Why is filter in brackets anyway?
      }
      }
      __________________
      Reply With Quote
        #3    
      Old July 31st, 2013 (6:20 PM).
      jcl's Avatar
      jcl jcl is offline
         
        Join Date: Jul 2013
        Gender: Female
        Posts: 40
        Thanks a million for replying -- you're the first person that has tried to help me. xD

        I have provided screenshots hoping that they will help explain my situation.

        This is my main timeline.


        This is what is inside the movieclip "hairWindow1"


        This is what is inside the movieclip "maleBodyHairFront"


        I have managed to get the color sliders to work on a separate FLA file, however, the file was very simple and only had the sliders convert the color of a single movieclip. In this situation, I want the sliders in frame 2 of "hairWindow1" to manipulate "maleBodyHairFront" and all of the movieclips inside of it.

        I have tried to insert your cleaner code but to no avail. I have also tried a myriad of other possible solutions but nothing seems to work. If this is not sufficient enough information for you then I can send you the source files.
        __________________
        This is my game!
        Reply With Quote
          #4    
        Old July 31st, 2013 (6:50 PM).
        th3shark's Avatar
        th3shark th3shark is offline
        Develops in AS3/C++
           
          Join Date: Jul 2013
          Location: Connecticut
          Gender: Male
          Nature: Calm
          Posts: 79
          I PM'd you a possible solution.
          __________________
          Reply With Quote
          Reply
          Quick Reply

          Sponsored Links
          Thread Tools

          Posting Rules
          You may not post new threads
          You may not post replies
          You may not post attachments
          You may not edit your posts

          BB code is On
          Smilies are On
          [IMG] code is On
          HTML code is Off

          Forum Jump


          All times are GMT -8. The time now is 11:18 PM.