So Confused, but not giving up

Ok the more I work with GameSalad, the more I start to understand it. At times I can visualize what I want to put in the code but cant actually do it. Haha

So I have a Player (actor) that starts off with the color set to white. I want to change that color to black when a button is pressed. Then if its pressed again change it back to white. So kind of a back and forth code.

Am I heading down the right path with what i have in my mind.

A game attribute boolean (check color) to check players color.
A game attribute integer (switch) set at 0, to check if the button is pressed.

Under the switch actor:
rule - when pressed - change attribute game.switch to 1

Under the player actor:

Rule
when game.switch = 1
when check color is true

change attribute to alpha 0

otherwise

change attribute to alpha 1

Comments

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    There are many ways that you can do things in Gamesalad, but one way that I like to make "switches" or "back and forth" actions work is to do the following:

    1. Make an integer attribute (game.changeColor)
    2. Make a rule that states when touch is pressed change game.changeColor to (game.changeColor + 1)%2
    3. Next make rules that state when game.changeColor = 1 -> change self.alpha to 1 when game.changeColor = 0 -> change self.alpha to 0
    4. This simple set of rules will act as a continuous button and allow you to click it and change the value every time. The formula (game.changeColor + 1)%2 saves you from writing more code than necessary, but don't forget the () :)
  • I_AM_BENJII_AM_BENJI USAMember Posts: 40

    From Scratch

    1. Make Attribute (integer)
    2. Go to button
    3. Rule touch is pressed change attribute to attribute+1
    4. Another Rule in button if attribute=3 then change attribute to 1
    5. go to player an make rule if attribute is = 1 change attribute to alpha 0
    6. another rule if attribute is =2 change attribute to alpha 1
  • BBEnkBBEnk Member Posts: 1,764

    Changing the Alpha to 0 will make actor invisible, to change back and forth from white to black try this. replace the touch rule with attribute.

    Learned this from @Socks‌

  • GamingtilDawnGamingtilDawn Member Posts: 104

    Thank you everyone.

    Matt that did work better and yes BBEnk I meant the RGB not alpha, thanks for catching that mistake.

Sign In or Register to comment.