我正在使用 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 显示所有消息,但不显示精灵。
所以如果可以的话,请告诉我有什么问题。提前致谢。