Esempio n. 1
0
void CharacterGame::play(const char* id, bool repeat, float speed)
{
    AnimationClip* clip = _animation->getClip(id);

    // Set clip properties
    clip->setSpeed(speed);
    clip->setRepeatCount(repeat ? AnimationClip::REPEAT_INDEFINITE : 1);

    // Is the clip already playing?
    if (clip == _currentClip && clip->isPlaying())
        return;

    if (_jumpClip->isPlaying())
    {
        _currentClip = clip;
        return;
    }

    // If a current clip is playing, crossfade into the new one
    if (_currentClip && _currentClip->isPlaying())
    {
        _currentClip->crossFade(clip, 150);
    }
    else
    {
        clip->play();
    }

    _currentClip = clip;
}
Esempio n. 2
0
void Animation::createClips(Properties* animationProperties, unsigned int frameCount)
{
    GP_ASSERT(animationProperties);

    Properties* pClip = animationProperties->getNextNamespace();

    while (pClip != NULL && std::strcmp(pClip->getNamespace(), "clip") == 0)
    {
        int begin = pClip->getInt("begin");
        int end = pClip->getInt("end");

        AnimationClip* clip = createClip(pClip->getId(), ((float)begin / frameCount) * _duration, ((float)end / frameCount) * _duration);

        const char* repeat = pClip->getString("repeatCount");
        if (repeat)
        {
            if (strcmp(repeat, ANIMATION_INDEFINITE_STR) == 0)
            {
                clip->setRepeatCount(AnimationClip::REPEAT_INDEFINITE);
            }
            else
            {
                float value;
                sscanf(repeat, "%f", &value);
                clip->setRepeatCount(value);
            }
        }

        const char* speed = pClip->getString("speed");
        if (speed)
        {
            float value;
            sscanf(speed, "%f", &value);
            clip->setSpeed(value);
        }

        clip->setLoopBlendTime(pClip->getFloat("loopBlendTime")); // returns zero if not specified

        pClip = animationProperties->getNextNamespace();
    }
}
Esempio n. 3
0
AnimationClip* AnimationClip::clone(Animation* animation) const
{
    // Don't clone the elapsed time, listeners or crossfade information.
    AnimationClip* newClip = new AnimationClip(getId(), animation, getStartTime(), getEndTime());
    newClip->setSpeed(getSpeed());
    newClip->setRepeatCount(getRepeatCount());
    newClip->setBlendWeight(getBlendWeight());
    
    size_t size = _values.size();
    newClip->_values.resize(size, NULL);
    for (size_t i = 0; i < size; ++i)
    {
        if (newClip->_values[i] == NULL)
        {
            newClip->_values[i] = new AnimationValue(*_values[i]);
        }
        else
        {
            *newClip->_values[i] = *_values[i];
        }
    }
    return newClip;
}