0

我正在使用 cocos2d 开发一些示例游戏以进行更多练习,但我的课程有问题。这是我的例子:

一些形状.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface palleteOfShapes : CCLayer 
{
    NSMutableArray *shapesArray;
}
@property (nonatomic,retain) NSMutableArray *shapesArray;
-(void)drawPallete;
@end

一些形状.m

#import "palleteOfShapes.h"

@implementation palleteOfShapes
@synthesize shapesArray;
-(void)drawPallete

{
    shapesArray = [NSMutableArray arrayWithObjects:@"Icon.png",@"A.png",@"questionMark.png",nil];
    for (int i=0; i<shapesArray.count; i++) {
        NSString *imagestring = [shapesArray objectAtIndex:i];
        CCSprite *sprite = [CCSprite spriteWithFile:imagestring];
         NSLog(@"i value: %i",i);
        sprite.position=ccp(100*i,350);
         NSLog(@"image added:%@",imagestring);
        [self addChild:sprite];
         NSLog(@"count: %d",[shapesArray count]);
    }        
    NSLog(@"pallete was completed");
    [shapesArray removeLastObject];
    NSLog(@"count:%d",[shapesArray count]);

}
@end

在我做的主层:

palleteOfShapes *newPallete = [[palleteOfShapes alloc]init];
[newPallete drawPallete];

我希望这些精灵会出现在我的主图层上,但它们没有。NSLog 显示所有消息,但不显示精灵。

所以如果可以的话,请告诉我有什么问题。提前致谢。

4

2 回答 2

0

实现-(id) init方法并在那里尝试一些初始化。

于 2012-05-05T19:18:19.627 回答
0

您将精灵添加到“palleteOfShapes”层,但您从未将它们或“palleteOfShapes”添加到主层。

于 2012-05-05T19:30:33.637 回答