@Override
 public void update(float timeDelta, BaseObject parent) {
   if (mRenderComponent != null && mDrawable != null) {
     if (timeDelta > mMaxFrameTimeMS) {
       mRenderComponent.setDrawable(mDrawable);
     } else {
       mRenderComponent.setDrawable(null);
     }
   }
 }
Exemplo n.º 2
0
  @Override
  public void update(float timeDelta, BaseObject parent) {
    if (mRenderComponent != null) {
      final TimeSystem time = sSystemRegistry.timeSystem;
      final float currentTime = time.getGameTime();

      // Support repeating "phases" on top of the looping fade itself.
      // Complexity++, but it lets this component handle several
      // different use cases.
      if (mActivateTime == 0.0f) {
        mActivateTime = currentTime;
        mInitialDelayTimer = mInitialDelay;
      } else if (mPhaseDuration > 0.0f && currentTime - mActivateTime > mPhaseDuration) {
        mActivateTime = currentTime;
        mInitialDelayTimer = mInitialDelay;
        mStartTime = 0.0f;
      }

      if (mInitialDelayTimer > 0.0f) {
        mInitialDelayTimer -= timeDelta;
      } else {
        if (mStartTime == 0) {
          mStartTime = currentTime;
        }
        float elapsed = currentTime - mStartTime;
        float opacity = mInitialOpacity;
        if (mLoopType != LOOP_TYPE_NONE && elapsed > mDuration) {
          final float endTime = mStartTime + mDuration;
          elapsed = endTime - currentTime;
          mStartTime = endTime;
          if (mLoopType == LOOP_TYPE_PING_PONG) {
            float temp = mInitialOpacity;
            mInitialOpacity = mTargetOpacity;
            mTargetOpacity = temp;
          }
        }

        if (elapsed > mDuration) {
          opacity = mTargetOpacity;
        } else if (elapsed != 0.0f) {
          if (mFunction == FADE_LINEAR) {
            opacity = Lerp.lerp(mInitialOpacity, mTargetOpacity, mDuration, elapsed);
          } else if (mFunction == FADE_EASE) {
            opacity = Lerp.ease(mInitialOpacity, mTargetOpacity, mDuration, elapsed);
          }
        }

        if (mTexture != null) {
          // If a texture is set then we supply a drawable to the render component.
          // If not, we take whatever drawable the renderer already has.
          final DrawableFactory factory = sSystemRegistry.drawableFactory;
          if (factory != null) {
            GameObject parentObject = ((GameObject) parent);
            DrawableBitmap bitmap = factory.allocateDrawableBitmap();
            bitmap.resize((int) mTexture.width, (int) mTexture.height);
            // TODO: Super tricky scale.  fix this!
            bitmap.setWidth((int) parentObject.width);
            bitmap.setHeight((int) parentObject.height);
            bitmap.setOpacity(opacity);
            bitmap.setTexture(mTexture);
            mRenderComponent.setDrawable(bitmap);
          }
        } else {
          DrawableObject drawable = mRenderComponent.getDrawable();
          // TODO: ack, instanceof!  Fix this!
          if (drawable != null && drawable instanceof DrawableBitmap) {
            ((DrawableBitmap) drawable).setOpacity(opacity);
          }
        }
      }
    }
  }