1

次のコードを見つけました。編集についてサポートが必要です。私はテクスチャレンダリングにあまり詳しくありません。

まず第一に、initメソッドはrectを取り、その領域のみを拡大しますか?どうすればそれをよりダイナミックにし、虫眼鏡の下にあるものだけを拡大することができますか?

第二に、形状を長方形ではなく円に変更することは可能ですか?または、画像を虫眼鏡のフレームとして使用できますか?

これがコードです。

乾杯..

.hファイル

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface Magnify : CCNode {

    BOOL active;
    CGRect rect;
    CGFloat magnifyScale;

    CCNode *renderNode;     
    CCRenderTexture *renderTexture;     

}

- (id)initWithNodeToMagnify:(CCNode *)n rect:(CGRect)rectToMagnify scale:(CGFloat)scale;
- (void)enable;
- (void)disable;

.mファイル

#import "Magnify.h"

@implementation Magnify

- (id)initWithNodeToMagnify:(CCNode *)n rect:(CGRect)rectToMagnify scale:(CGFloat)scale
{
    if (self = [super init]) {

        self.visible = active = NO;
        renderNode = n;
        rect = rectToMagnify;
        magnifyScale = scale;

        renderTexture = [[CCRenderTexture renderTextureWithWidth:rect.size.width height:rect.size.height] retain];
        [self addChild:renderTexture];

    }
    return self;
}


- (void)enable
{
    self.visible = active = YES;
    [self scheduleUpdate];
}

- (void)disable
{
    self.visible = active = NO;
    [self unscheduleUpdate];
}

- (void)drawAreaToTexture
{
    [renderTexture beginWithClear:0.0 g:0.0 b:0.0 a:1.0];
    // shift the renderNode's position to capture exactly the rect we need
    CGPoint originalPosition = renderNode.position;

    renderNode.position = ccpSub(originalPosition, rect.origin);

    // scale the node as we want
    CGFloat originalScale = renderNode.scale;
    renderNode.scale = magnifyScale;

    [renderNode visit];

    // shift renderNode's position back
    renderNode.position = originalPosition;

    // scale back
    renderNode.scale = originalScale;

    [renderTexture end];
}

- (void)update:(ccTime)dt
{
    [self drawAreaToTexture];
}

- (void)dealloc
{
    [renderTexture release];
    [super dealloc];
}

@end
4

1 に答える 1

0

さて、このようなものについて上で述べたように、考えられる答えの 1 つは、CCLens3D クラスを使用して何かを円形に拡大する「効果」を得ることです。

「シーン」の最上位ノードの子でない限り機能しないように見えるため、これを使用するのは少し難しいことがわかりました。

画面上を移動してから消えるレンズを作成するために使用するコードを次に示します。

    // Create the lens object first.
    //
    CCLens3D *lens = 
       [CCLens3D actionWithPosition:fromPos 
                             radius:50 
                               grid:ccg(50, 50) 
                           duration:2.0];

    // Set the "size" of the lens effect to suit your needs.
    //
    [lens setLensEffect:1.0];

    // In my case, I then move the lens to a new position.  To apply an action on
    // a lens, you need to give the actions to the actionManager in the
    // CCDirector instance.
    //
    CCMoveTo *move = [CCMoveTo actionWithDuration:2.0 position:toPos];

    // I had another action in this array, but this will do.
    //
    CCSequence *seq = [CCSequence actions:move, nil];

    // Now tell the actionManager to move the lens.  This is odd, but it works.
    //
    [[[CCDirector sharedDirector] actionManager] addAction:seq target:lens paused:NO];

    // Now just for some more weirdness, to actually make the lens appear and operate
    // you run it as an action on the node it would normally be a child of.  In my case
    // 'self' is the CCLayer object that is the root of the current scene.
    //
    // Note that the first action is the lens itself, and the second is a special
    // one that stops the lens (which is a "grid" object).
    //
    [self runAction:[CCSequence actions:lens, [CCStopGrid action], nil]];

必要なときに CCStopGrid アクションを実行することで、グリッドを停止できるはずだと思います。私の場合、それはプログラムされたものです。あなたの場合、ユーザーがボタンを離したときかもしれません。

于 2013-04-04T09:52:57.110 に答える