Is it possible to swap actors - logic and all
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
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
-
BrynjeBamsen Posts: 188
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
-
jckmcgraw Posts: 647
@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 -
BrynjeBamsen Posts: 188
hehe true - jack is right.
minor brainfart, other then that i should work out fine
Answers
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS