CGpoint到NSMutableArray中的CCmenuItem

时间:2012-06-13 20:30:24

标签: xcode

    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]];
    }

我试图制作一个平铺游戏但是卡住了。 看到这条线&#34;这是错误的&#34;。我试图将CGPoint坐标从gridPointArray传递到BrickornaArray中的CCmenuItem(bricka),但没有运气。我无法弄清楚它的语法。

1 个答案:

答案 0 :(得分:0)

CCMenuItemImage没有名为“CGPointValue”的属性 - 它具有 type CGPointValue属性,名为position,这是您应该设置的。

类似的东西:

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

在CCNode中声明position属性,CCMenuItem(和CCMenuItemImage)从该属性继承。