Try the State Pattern. I have successfully used this in a line of games
I did for a client.
The Quick and Dirty explanation:
Each state knows what it needs to do. On a change state the old state
exits and the new state enters. On
an update (onEnterFrame) the state is handled (it does what it needs to
accomplish). Any state can be interrupted to go into another state.
Each state implements an interface.
In my games I had a hierarchical state pattern (states within states)
and the root state was in the game manager
which held all the game logic methods that states could use to
accomplish whatever task they wanted.
More info (cleaner and clearer) here:
http://www.ai-junkie.com/architecture/state_driven/tut_state1.html
Ciao,
Rob.
James Marsden wrote:
Hey Dan,
I've had a bit of a struggle with this too. I've tried a few ways of
doing it, but have settled on having all state/animations in a
MovieClip on the first frame of the character MovieClip, and then
functions to show and hide whichever animations you need eg:
turnRightFromLeft()
{
paddleLeftMC.visible = false;
idleLeftMC.visible = false;
idleRightMC.visible = false
idleCentre.gotoAndPlay("turnRightFromLeft"); // at the end of this
animation, it calls back to set 'paddleRightMC.visible = true';
}
It's quite long winded, and you still need a state machine to work out
which functions you need to call, but the other ways I tried were
vastly more complex, and introducing a new animation at a later date
was a real headache.
HTH,
James
Holth, Daniel C. wrote:
Hello,
I'm working on an project where the user uses the arrows keys to move a
guy in a kayak left and right across the screen. I have 6 total
animations set up: Paddling Left, Idle Facing Left, Turning Left to
Right, Paddling Right, Idle Facing Right, and Turning Right To Left.
I've never programmed a moving character before, so I'm looking for some
tips on the best way to program this sort of thing. I started to create
a pseudo-state pattern using a 6 switch statement to figure out what
state the character is currently in and responding accordingly when the
user presses a key. This seems rather tedious though, and I figured
there must be a better way of doing this.
I think the part I'm having the most trouble with is the 'turning
states'.
Any feedback greatly appreciated! I can post some of my current code if
it helps, but I really haven't gotten anywhere productive with it yet.
Thanks!
Daniel Holth
I.S. Programmer
This e-mail and its attachments are intended only for the use of the
addressee(s) and may contain privileged, confidential or proprietary
information. If you are not the intended recipient, or the employee
or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution, displaying, copying, or use of this information is
strictly prohibited. If you have received this communication in
error, please inform the sender immediately and delete and destroy
any record of this message. Thank you.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com