5 Replies Latest reply on May 28, 2006 4:54 PM by ManOfMac

    Displaying colour using ticks

    Bhavzzz
      Hi,

      I need some help with a game I’m designing. The following code identifies the key pressed and counts the time it stays down which determines the shade of a particular colour, for example if you pressed 'A' the colour selected would be RED and how dark or light the colour is is determined by how long you hold the key down, the longer you hold, the darker the colour etc... However the code seems to work when I only specify a particular key and colour but as soon as I start to add more keys and colours the code doesn’t seem to work. Which I find very confusing , any help would be greatly appreciated and thank you in advance.

      vRandomRed = 46+integer(pressed_time*16/100)—I’m using ticks for timing and 100 to keep the number reasonable
      vColour = paletteIndex(vRandomRed)
      sprite(vSquare).color = vColour –sprite on stage

      The above code fills a sprite on stage with the shade/tint of red, which works fine, but the code below does not

      vRandomRed = 46+integer(pressed_time*16/100)
      vRandomPink = 68+integer(pressed_time*16/100)
      vRandomOrange = 24+integer(pressed_time*16/100)

      case the keyPressed of
      "A": vColour = paletteIndex(vRandomRed)
      "B": vColour = paletteIndex(vRandomPink)
      "C": vColour = paletteIndex(vRandomOrange)
      end case

      sprite(vSquare).color = vColour
        • 1. Re: Displaying colour using ticks
          ManOfMac
          What errors are you getting ?
          Are the numbers within the limits of the colour space
          I assume sprite(Vsqaure) has a proper value ie. below 255
          Try:
          "C": vColour = IntpaletteIndex(vRandomOrange)
          AND
          sprite(Vsqaure).color = color(vRandomOrange)

          ????
          • 2. Re: Displaying colour using ticks
            Bhavzzz Level 1
            Hi,

            Thanks for the reply, however I still have problems. The error I get is 'Variable used before assigned a value' when I use the code you provided

            -- vRandomRed = 46+integer(pressed_time*16/100)
            -- vRandomPink = 68+integer(pressed_time*16/100)
            vRandomOrange = 24+integer(pressed_time*16/100)

            case the keyPressed of
            -- "A": vColour = paletteIndex(vRandomRed)
            -- "B": vColour = paletteIndex(vRandomPink)
            "C": vColour = intpaletteIndex(vRandomOrange) AND sprite(vSqaure).color
            end case

            and with my initial code I get this error 'Color expected'

            vRandomRed = 46+integer(pressed_time*16/100)
            vRandomPink = 68+integer(pressed_time*16/100)
            vRandomOrange = 24+integer(pressed_time*16/100)

            case the keyPressed of
            "A": vColour = paletteIndex(vRandomRed)
            "B": vColour = paletteIndex(vRandomPink)
            "C": vColour = paletteIndex(vRandomOrange)
            end case
            sprite(vSquare).color = vColour

            and vSquare is just a simple sprite on stage with forecolor of 240, and the event in question is triggered on keyUp and the counter starts the ticks on keyDown event. Hope you can help.
            • 3. Re: Displaying colour using ticks
              ManOfMac Level 1
              sprite(vSquare).color = vColour --WRONG
              sprite(vSquare).color = color(vColour ) --CORRECT
              • 4. Re: Displaying colour using ticks
                Bhavzzz Level 1
                Hi again,

                Sorry for not getting back earlier, however I still seem to have problems with this code none of the code that you have given me or anything I have tried seems to make it work . Am I doing something seriously wrong here, I don't know but I have not progressed at all with this problem. I know I might be asking for a lot but I’m really stuck with this so if you have any other solution to this please guide me know.

                Thanks again
                • 5. Re: Displaying colour using ticks
                  ManOfMac Level 1
                  Havent worked alot with colour & paletteIndex put have tried this and it works!!

                  I have modified your code to this:

                  vRandomRed = 46+integer(pressed_time*16/100) --All good gives a numnber
                  vRandomPink = 68+integer(pressed_time*16/100) --All good gives a numnber
                  vRandomOrange = 24+integer(pressed_time*16/100) --All good gives a numnber

                  case the keyPressed of
                  "A": vColour = vRandomRed --Assign that number to the variable vColour
                  "B": vColour = vRandomPink --Assign that number to the variable vColour
                  "C": vColour = vRandomOrange --Assign that number to the variable vColour
                  end case

                  sprite(vSquare).color = color(vColour) --Apply the variable colour to the sprite
                  updateStage --Force the stage to update the color !!

                  The whole "paleteIndex" thing was giving me a headache when it wasnt really neccessary !!