0
我一直在为此苦苦挣扎。我试图避免为我想创建的对象创建多个类。基本上我有一个'Letter'类,它有一个字母属性。当我初始化对象时,我将字母类型设置为A,B,C ...我在循环中完成这一切。一切似乎都很好。Cocos2D ccTouchesMoved Sprite and Objects
问题是当我发射ccTouchesMoved事件我想知道如果我正在移动类型A或B等字母对象..我无法弄清楚这一个。
下面是一些片段,显示我在做什么:
信类
@implementation Letter
- (id)init {
if ((self = [super init])) {
gamePieceType = kLetterNotAssigned;
}
return self;
}
我的层初始化
for (int x=0; x < NUMBER_OF_ITEMS; x++) {
int randomX = random() % 1024;
[self createPuzzlePieceAtLocation:ccp(randomX, 600) withPiece:x];
}
的createPuzzlePieceAtLocation方法
- (void)createPuzzlePieceAtLocation:(CGPoint)location
withPiece:(int)tagValue {
switch (tagValue) {
case 1:
letterSprite = [[Letter alloc] initWithSpriteFrameName:@"upper_a.png"];
letterSprite.gamePieceType = kLetterA;
break;
...
}
[self createBodyAtLocation:location forSprite:letterSprite isBox:FALSE];
[sceneSpriteBatchNode addChild:letterSprite];
有什么想法?我在ccTouchesMoved中获得了touchLocation,但是如何获取对象?