0

hexTouchAreasメソッドの戻り値として取得しますが-drawHexagonTouchArea、プロジェクトを分析すると、CGMutablePathRef hexTouchArea = CGPathCreateMutable();「初期化中に「hexTouchArea」に保存された値は読み取られません」という警告が表示される行が表示されます。そして、CGPathRelease(hexTouchArea);私はそのオブジェクトを所有しておらず、それを解放するのは不必要であると不平を言う行で.

もう 1 つの警告はreturn path;、Analyzer が次のように言う行にありますCGMutablePathRef path = CGPathCreateMutable();

-(void)createTouchAreas{

    int realPositionsCount =[[GameStateSingleton sharedMySingleton]getSharedRealCountOfPositions]; 
    hexTouchAreas = [[GameStateSingleton sharedMySingleton]getSharedHexTouchAreas];
    NSMutableDictionary *existingHexagons = [[GameStateSingleton sharedMySingleton]getExistingHexagons];
    for (int i = 0; i <= realPositionsCount;i++){
        //create touchareas
        NSString *hexKey = [NSString stringWithFormat:@"hexagon%d", i];
        CCSprite *theSprite = [[existingHexagons objectForKey:hexKey]objectForKey:@"realSprite"];
        CGPoint touchAreaOrigin = ccp(theSprite.position.x -22, theSprite.position.y-40);
        NSString *touchAreaKey = [NSString stringWithFormat:@"hexTouchArea%d",i];
        CGMutablePathRef hexTouchArea = CGPathCreateMutable();
        hexTouchArea = (CGMutablePathRef) [self drawHexagonTouchArea:touchAreaOrigin];
        [hexTouchAreas setObject:(id)hexTouchArea forKey:touchAreaKey];
        [[GameStateSingleton sharedMySingleton]setSharedHexTouchAreas:hexTouchAreas];
        CGPathRelease(hexTouchArea);

    }



}

パスを作成して返すメソッド:

-(CGMutablePathRef)drawHexagonTouchArea:(CGPoint)origin
{   


    CGMutablePathRef path = CGPathCreateMutable();
    CGPoint newloc = CGPointMake(origin.x, origin.y);

    CGPathMoveToPoint(path, NULL, newloc.x, newloc.y);
    CGPathAddLineToPoint(path, NULL, newloc.x -22,newloc.y + 38);
    CGPathAddLineToPoint(path, NULL, newloc.x + 0, newloc.y + 76);
    CGPathAddLineToPoint(path, NULL, newloc.x + 46,  newloc.y + 76);
    CGPathAddLineToPoint(path, NULL, newloc.x +66,newloc.y + 40);
    CGPathAddLineToPoint(path, NULL, newloc.x +44, newloc.y + 0);
    CGPathCloseSubpath(path);
    return path;
}
4

1 に答える 1

1

次のコードを使用して、可変パスを作成し、それをhexTouchAreaに割り当ててから、hexTouchAreaを別の作成されたオブジェクトで上書きします。

CGMutablePathRef hexTouchArea = CGPathCreateMutable();
hexTouchArea = (CGMutablePathRef) [self drawHexagonTouchArea:touchAreaOrigin];

おそらく使いたいものは次のとおりです。

CGMutablePathRef hexTouchArea = [self drawHexagonTouchArea:touchAreaOrigin];
于 2012-09-13T20:26:49.637 に答える