-1

スプライトにハイライト アニメーションを実装しようとしています。次のコードを使用して、スプライトを特定の色にハイライトし、徐々に元の色に戻します。

- (void)highlight {
    CCTintTo *tintAction = [CCTintTo actionWithDuration:0.1 red:255 green:255 blue:255];
    CCTintTo *tintBackAction = [tintAction reverse];

    CCSequence *sequence = [CCSequence actions: tintAction, tintBackAction, nil];
    [self runAction:sequence];
}

CCTintTo が「リバース」を実装していないように見えるため、この関数は例外を発生させますが、これは理にかなっています。CCAction を使用して、ある間隔で追加された色合いの削除を実装する他の方法はありますか?

4

3 に答える 3

3
  1. CCSpriteのデフォルトの色はccWhite{255、255、255}であるため、スプライトを明るくしたい場合は、CCSprite加法色を使用するために/writeシェーダーをサブクラス化する必要があります。

  2. ただそれを元に戻します:

    CCColor3B oldColor = sprite.color;
    CCTintTo *tintTo = [CCTintTo actionWithDuration:t red:r green:g blue:b];
    CCTintTo *tintBack = [CCTintTo actionWithDuration:t red:oldColor.r green:oldColor.g blue:oldColor.b];
    [sprite runAction:[CCSequence actions: tintTo, tintBack, nil]];
    
于 2012-10-26T18:16:50.713 に答える
0

色合いを開始する前に前の色を保存してから、初期 RGB 値で CCTintTo を作成するだけです。

于 2012-10-26T12:13:35.427 に答える
0

Cocos2dx (C++) の場合

ccColor3B oldColor = sprite->getColor();
        CCTintTo* action = CCTintTo::create(0.5f, 127, 255, 127);
        CCTintTo* actionReverse = CCTintTo::create(0.5f, oldColor.r, oldColor.g, oldColor.b);;
        sprite->runAction(CCSequence::create(action, actionReverse, NULL));

うまくいきます クレイリ、ありがとう!私はすでにあなたにプラスを与えました:)。

于 2014-12-31T23:07:55.640 に答える