用于绘制精灵的单独类,类不起作用

时间:2012-05-05 18:58:22

标签: iphone objective-c ios sprite

我正在使用cocos2d进行一些示例游戏以获得更多练习,但我遇到了课程问题。这是我的例子:

someShapes.h

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

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

someShapes.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显示所有消息但没有精灵。

如果可以的话,请告诉我出了什么问题。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您可以将精灵添加到“palleteOfShapes”图层,但不要将它们或“palleteOfShapes”添加到主图层。