0

私は cocos2d の初心者で、塗り絵アプリで作業しています。描画には CCRenderTexture を使用しています。

target = [[CCRenderTexture alloc] initWithWidth:size.width height:size.height pixelFormat:kCCTexture2DPixelFormat_RGBA8888];
            [target setPosition:ccp(size.width/2, size.height/2)];
    [target clear:255 g:255 b:255 a:1];
    [self addChild:target];

しかし、画面の下部に隠れるサブメニューを表示するには、描画領域 (CCRenderTexture) の位置を少し上に移動する必要があるため、CCMove を使用しています。

[CCMoveTo actionWithDuration:0.2 position:ccp(self.position.x, self.position.y+menuOffset)]

rendertexture は期待どおりに上に移動しますが、「タッチ可能な領域」は同じ場所にとどまるため、サブメニュー領域 (rendertexture フレームの外側) に触れると、rendertexture 内にまだ描画されます。

これが描画方法です

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

        UITouch *touch = [touches anyObject];
        CGPoint start = [touch locationInView: [touch view]];
        start = [[CCDirector sharedDirector] convertToGL: start];
        CGPoint end = [touch previousLocationInView:[touch view]];
        end = [[CCDirector sharedDirector] convertToGL:end];

        // begin drawing to the render texture
        [target begin];
        // scale/rotation/offset
        float distance = ccpDistance(start, end);
        if (distance > 1)
        {
                int d = (int)distance;
                for (int i = 0; i < d; i++)
                {
                        float difx = end.x - start.x;
                        float dify = end.y - start.y;
                        float delta = (float)i / distance;
                        [brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))];
                        [brush setRotation:rand()%360];
                        [brush setScale:drawratio];
                        [brush setColor:brush.color];
                        [brush visit];
                }

        }
        [target end];

}

では、CCRendertexture の位置を適切な方法で変更するにはどうすればよいですか? 前もって感謝します。

4

1 に答える 1

1

GL 座標をターゲットオブジェクトのノード空間に変換するだけです。

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint start = [touch locationInView: [touch view]];
    start = [[CCDirector sharedDirector] convertToGL: start];
    start = [target convertToNodeSpace: start];

    CGPoint end = [touch previousLocationInView:[touch view]];
    end = [[CCDirector sharedDirector] convertToGL:end];
    end = [target convertToNodeSpace: end];

    // begin drawing to the render texture
    [target begin];
    // scale/rotation/offset
    float distance = ccpDistance(start, end);
    if (distance > 1)
    {
            int d = (int)distance;
            for (int i = 0; i < d; i++)
            {
                    float difx = end.x - start.x;
                    float dify = end.y - start.y;
                    float delta = (float)i / distance;
                    [brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))];
                    [brush setRotation:rand()%360];
                    [brush setScale:drawratio];
                    [brush setColor:brush.color];
                    [brush visit];
            }

    }
    [target end];

}
于 2013-03-04T03:05:09.323 に答える