Is it possible to swap actors - logic and all

vikingviking Member, PRO Posts: 322
edited May 2012 in Working with GS (Mac)
Quick question: Anyone know if there is a simple and elegant way to swap two actors?

I have one actor with its unique set of behaviors. Let's say it is called RED and it is on the left hand side of the screen. My other actor is called BLACK with its own set of unique behaviors on the right side of the screen. I activate my "RED to BLACK actor swap power-up" by tapping the power-up icon in the middle of the screen. Then I tap the BLACK actor on the right who then instantly becomes my RED actor (image, sounds, etc - but most importantly I need the behaviors swapped as well).

I tried to swap images and that was simple enough, but my logic will not work since the game still considers my RED actor the original BLACK actor. I also considered swapping X and Y positions between the two actors, but I think that will cause some problems since I am using physics and both actors RED and BLACK have other actors below them and above them with gravity turned on.

Anyone else had a problem like this and found a solution? Any suggestions?

-E

Best Answers

  • BrynjeBamsenBrynjeBamsen Posts: 188
    Accepted Answer
    1: Make an integer game attribute called swap - set it to 1
    2: Go to your "RED" actor create two new rules
    3: put all RED actor behaviors in the first rule and have it say
    If game attribute.game.swap = 1
    Then use all the RED bahaviors
    4: in rule 2 put all the BLACK behaviors in the second rule on the RED actor.
    If game attribute.game.swap = 2
    5:Then use all the BLACK behaviors

    --------------------------------------

    Now you do the exact same thing on your BLACK actor - but change RED til 2 and BLACK to 1

    6: On your Power-Up you put in a new rule
    If touch is pressed
    change attrbute.game.swap to (game.swap+1)%2

    If you keep touching the Power-up it will toggle between 1 and 2 and thereby swapping the behaviors

    Later
  • jckmcgrawjckmcgraw Posts: 647
    Accepted Answer
    @BrynjeBamsen

    When you do: change attribute game.swap to game.swap+1)%2 it will switch the #'s between 0 and 1 (not 1 and 2).

    So in the rules you would want when game.swap = 1 do the native actor's rules. Otherwise: (accounting for the 0) do the other rules.

    Let me know if I am wrong about that.
    Jack McGraw
  • BrynjeBamsenBrynjeBamsen Posts: 188
    Accepted Answer
    hehe true - jack is right.
    minor brainfart, other then that i should work out fine

Answers

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited May 2012
    I always like to use 1 and 2 as it keeps zero as a neutral position Incase the attribute resets on a game restart. So I would make the switch as an otherwise rule. So in the main rule it functions as normal and then in the otherwise of that main rule add a rule with the attribute if actor=1 then do these rules, that way the main rule is always the default.
  • vikingviking Member, PRO Posts: 322
    Thanks guys. I will give it a shot. I have four fairly complex actors with about 50 rules in each of them, so adding all the behaviors of the other three in each of the actors will make them really heavy. However, this may be the only way to do it.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I've made actors with major depths of otherwise commands. The great thing about using otherwise if the first condition is not enabled it will skip the rest of the code so it doesn't make your code heavy.
Sign In or Register to comment.