2012-06-13 18 views
0
brickorna = [NSMutableArray arrayWithCapacity:10]; 

    int chipSize = 100; 
    gridPoints = [NSMutableArray arrayWithObjects: 
        [NSValue valueWithCGPoint:CGPointMake(chipSize, chipSize)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*2, chipSize)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*3, chipSize)], 

        [NSValue valueWithCGPoint:CGPointMake(chipSize, chipSize*2)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*2, chipSize*2)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*3, chipSize*2)], 

        [NSValue valueWithCGPoint:CGPointMake(chipSize, chipSize*3)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*2, chipSize*3)], 
        [NSValue valueWithCGPoint:CGPointMake(chipSize*3, chipSize*3)], 
        nil]; 


    for (int i = 0; i <= 8; i++) { //createing chips and adding them to array 
    CCMenuItemImage *bricka = [CCMenuItemImage itemFromNormalImage:@"Icon.png" selectedImage:nil]; 
     [brickorna addObject:bricka]; 
    } 

    for (int a = 0; a <= 8; a++) { //adding the chips to scene 

     CCMenuItemImage *tempB = [brickorna objectAtIndex:a]; 
     tempB.position = [[gridPoints objectAtIndex:a] CGPointValue]; 

     [self addChild:[brickorna objectAtIndex:a]]; 
    } 

我試圖做一個瓷磚遊戲,但卡住了。 看到「這是錯誤的」一行。我試圖將CGPoint座標從gridPointArray傳遞給BrickornaArray中的CCmenuItem(bricka),但沒有運氣。我無法弄清楚它的語法。CGpoint到NSMutableArray中的CCmenuItem

回答

0

一個CCMenuItemImage沒有一個名爲「CGPointValue」屬性 - 它有 CGPointValue,命名爲position,這是什麼,你應該設置的屬性。

是這樣的:

[brickorna objectAtIndex:a].position = [[gridPoints objectAtIndex:a] CGPointValue]; 

position屬性在CCNode聲明,從中CCMenuItem(和CCMenuItemImage)繼承。