16

透明度のある PNG 画像から作成されたいくつかのレイヤーがあるアプリがあります。これらのレイヤーはすべて画面上で重なり合っています。ユーザーがレイヤーの透明でない領域をタップしたときに、レイヤーの透明な領域に与えられたタッチを無視し、タッチとして検出できるようにする必要があります...写真を参照してください...

ここに画像の説明を入力

それ、どうやったら出来るの?ありがとう。

4

4 に答える 4

6

ここに可能な解決策があります。

CCLayer に拡張機能を実装し、次のメソッドを提供します。

- (BOOL)isPixelTransparentAtLocation:(CGPoint)loc 
{   
    //Convert the location to the node space
    CGPoint location = [self convertToNodeSpace:loc];

    //This is the pixel we will read and test
    UInt8 pixel[4];

    //Prepare a render texture to draw the receiver on, so you are able to read the required pixel and test it    
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    CCRenderTexture* renderTexture = [[CCRenderTexture alloc] initWithWidth:screenSize.width
                                                                     height:screenSize.height
                                                                pixelFormat:kCCTexture2DPixelFormat_RGBA8888];

    [renderTexture begin];

    //Draw the layer
    [self draw];    

    //Read the pixel
    glReadPixels((GLint)location.x,(GLint)location.y, kHITTEST_WIDTH, kHITTEST_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, pixel);

    //Cleanup
    [renderTexture end];
    [renderTexture release];

    //Test if the pixel's alpha byte is transparent
    return (pixel[3] == 0);
}
于 2012-06-05T08:09:01.657 に答える
0

リオの解決策が機能しない場合は、透明なスプライトを自分の子として追加し、この非透明領域のサイズで非透明領域のすぐ下に配置し、この新しい透明スプライトによってすべてのタッチに抵抗することができますが、オリジナルスプライト。

于 2012-06-05T09:33:41.193 に答える
-1

私にとってうまくいった解決策は、スプライトシートを使用することでした。TexturePacker を使用してスプライト シートを作成します。TexturePacker を使用してスプライト シートを作成する手順: 1. すべての画像 (.png) ファイルを TexturePacker にロードします。2. データ形式として coco2d を選択し、テクスチャ形式として PVR を選択します。3. スプライト シートをコードに読み込み、スプライト シートから画像を抽出します。

詳細な説明はここにあります。

于 2014-09-10T10:33:18.610 に答える