Пример #1
0
        public void SetState(string state)
        {
            Validate();

            AnimationState tmp = GetState(state);
            if (tmp == null)
                throw new AnimationOperationException("Bad animation state : " + state);
            else
            {
                _currentState = tmp;
                _tick = 0;
                _currentFrame = 0;
                _frameHasChanged = true;
            }
        }
Пример #2
0
        public void Update(int elapsed)
        {
            Validate();

            _tick += elapsed;
            if (_tick >= _currentState.switchdelay)
            {
                _currentFrame++;
                if (_currentFrame >= _currentState.framecount)
                {
                    _currentFrame = 0;
                    if (!_currentState.IsLooped())
                        _currentState = GetState(_currentState.nextstate);
                }
                _frameHasChanged = true;
                _tick = 0;
            }
        }
Пример #3
0
        private void Validate()
        {
            if (_hasBeenValidated)
                return;

            bool hasNormal = false;

            int y_offset = 0;
            foreach (AnimationState st in states)
            {
                if (st.name == "normal")
                    hasNormal = true;
                if (GetState(st.nextstate) == null)
                    throw new AnimationOperationException("The next state " + st.nextstate + " of " + st.name + " has not been defined");
                if (st.framecount <= 0)
                    throw new AnimationOperationException("Invalid frame count on state " +  st.name);
                if (st.switchdelay < 0)
                    throw new AnimationOperationException("Invalid switch delay on state " + st.name);
                if (st.height < 0)
                    throw new AnimationOperationException("Invalid height on state " + st.name);
                if (st.width < 0)
                    throw new AnimationOperationException("Invalid width on state " + st.name);
                st.SetYOffset(y_offset);
                y_offset += st.height;
            }

            if (!hasNormal)
                throw new AnimationOperationException("The spritesheet requires the animation state 'normal'");

            _currentState = GetState("normal");
            _hasBeenValidated = true;
        }