0

我想要实现的是更改 mRectangles 属性,例如用户在设置中更改它的持续时间。我已经读过我想将 modifier.reset() 与原始的相应参数一起使用。我似乎无法弄清楚我应该在第四个参数中传递什么。我应该调用一个变量或函数来获得正确的上下文吗?

 @Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
    // TODO Auto-generated method stub

    Rectangle mRectangle = new Rectangle(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT,
            mEngine.getVertexBufferObjectManager());

    // With this anonymous function, you can add events to the beginning and end
    // of the modified state
    IEntityModifierListener mIEntityModifierListener = new IEntityModifierListener() {

        @Override
        public void onModifierStarted(IModifier<IEntity> pModifier,
                IEntity pItem) {
            // Grab the current duration value and compare it to the
            // one that's stored
            final int mDuration = (int) pModifier.getDuration();
            Log.i("MODIFIER", "Current duration value: " + mDuration);

            if(mDuration != mDurationPref)
            {
                Log.i("UPDATEDURATION","Duration value: " + mDurationPref);
                mFinalDuration = mDurationPref;

                pModifier.reset();

            }
            else
            {
                Log.i("UPDATEDURATION","Both values match: " + COLORONE_DEFAULT);
                mFinalDuration = COLORONE_DEFAULT;
            }

        }

        @Override
        public void onModifierFinished(IModifier<IEntity> pModifier,
                IEntity pItem) {
            // TODO Auto-generated method stub
            Log.i("MODIFIER", "It finished!");

        }
    };

    Log.i("FINALDURATIONVALUE", "Final duration: " + mFinalDuration);
    // This is where you can chain up the colors
    // TODO: Make this in to a function that interpolates the colors together
    ColorModifier mColorModifier = new ColorModifier(5, Color.CYAN,
            Color.RED, mIEntityModifierListener, EaseSineIn.getInstance());
    ColorModifier tColorModifier = new ColorModifier(5, Color.RED,
            Color.CYAN, EaseSineInOut.getInstance());
    ColorModifier iColorModifier = new ColorModifier(5, Color.CYAN,
            Color.GREEN, mIEntityModifierListener, EaseSineIn.getInstance());
    ColorModifier xColorModifier = new ColorModifier(5, Color.GREEN,
            Color.YELLOW, EaseSineInOut.getInstance());
    ColorModifier yColorModifier = new ColorModifier(5, Color.YELLOW,
            Color.CYAN, mIEntityModifierListener, EaseSineIn.getInstance());

    // The sequence modifier will go through the color modifiers
    // and the loop entity modifier makes it continuous 
    SequenceEntityModifier mSequenceEntityModifier = new SequenceEntityModifier(
            mColorModifier, tColorModifier, iColorModifier, xColorModifier,
            yColorModifier);
    LoopEntityModifier mLoopEntityModifier = new LoopEntityModifier(
            mSequenceEntityModifier);

    mRectangle.registerEntityModifier(mLoopEntityModifier);

    scene.attachChild(mRectangle);

    pOnPopulateSceneCallback.onPopulateSceneFinished();

}
4

1 回答 1

1

有两种方法可以做到这一点。您可以尝试覆盖修饰符中的内置方法(即,您可以@override onUpdate())并在那里执行您自己的逻辑,或者您可以使用更简单的方法:剥离现有修饰符并堆叠在新的修饰符上那些。

您在评论中提到,“我尝试清除并添加另一种颜色修饰符,但没有成功,”但没有详细说明原因。如果您的意思是您收到了一些错误,请发布错误消息,我们可以讨论它。如果您的意思是您没有从现有颜色到新颜色的“平滑”过渡(这是有道理的),那么您应该做的是让新修饰符从当前现有值开始。换句话说,在执行颜色修改器时,您为其提供“From”和“To”颜色,使用 mRectangle.getColor() 作为“From”,这样您就可以从当前所在的任何位置开始过渡。

于 2013-02-26T00:12:38.890 回答