Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a sprites behaviour at run time

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I wonder if anyone can help me with this problem I am having?

I have a sprite (cast member1) with a behaviour(Behaviour1) that I am changing during runtime to a different cast member(cast member2), which I want to have a different behaviour(Behaviour2) attached. So when I switch the sprites cast member1 to cast member2, how would I remove Behaviour1 from it and add Behaviour2. By the way the cast members are being switched in Behaviour1, so I cant see a way to remove the behaviour and attach behaviour2 from within behaviour1's script.

Any help on this problem much appreciated.
 
I do not know exactly the interaction you are trying to accomplish, but have you thought of using global variables?
What triggers the switch in cast members/behavoir?
Whatever that is could switch the cast member and change the value of a global variable. possibly in the same handler create an if then statement that calls a different handler in the same behavoir once the value of the global changes. (this other handler would basically be the bahvoir for the other castmember). Then once the condition occurs that would set the original cast member back to the sprite change the value of the global back to its original value.



 
more ways to do it than I can think of.

Globals as stated above would work.

Next trick is to have code attach behaviour2 to the sprite. The last thing behaviour1 does is remove itself. Because behaviours are processed in the order they are on the sprite behaviour1 will finish processing before behaviour2 starts operating. You avoid globals and big ugly if then statements.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top