Beispiel #1
0
        public MyStatefulAnimatedSpriteState GetState(string stateName)
        {
            // Validate the input parameter
            if (stateName == null || stateName.Length == 0)
            {
                throw new ArgumentException("Invalid state name");
            }

            // Try to find the state
            MyStatefulAnimatedSpriteState ret = null;

            States.TryGetValue(stateName, out ret);

            // If not found, then throw an exception, informing the caller that the state name is wrong
            if (ret == null)
            {
                throw new ArgumentException("Cannot find a state named [" + stateName + "]");
            }

            // If found, then return a reference
            return(ret);
        }
Beispiel #2
0
        /**
         * This works somewhat like a method of a builder class, to help chain up
         * multiple state-adding operations.
         */
        public MyStatefulAnimatedSprite WithState(string stateName, MyStatefulAnimatedSpriteState State)
        {
            // Make sure the parameters are ok, to avoid runtime errors
            if (stateName == null)
            {
                throw new ArgumentException("Each state must have a name");
            }
            if (State == null)
            {
                throw new ArgumentException("The state may not be null");
            }

            // Add the state. Override any pre-existing state with the same name.
            States.Add(stateName, State);

            // If this is the first state added, then make it the current state.
            if (CurrentState == null)
            {
                SetStateObject(State);
            }

            // Return a self reference to allow queuing the next WithState operation
            return(this);
        }
Beispiel #3
0
 private void SetStateObject(MyStatefulAnimatedSpriteState State)
 {
     CurrentState           = State;
     isBackgroundTransparet = State.IsBackgroundTransparent();
 }