20個のスプライトを持っています.20個のスプライトすべてがMutableArrayに追加されます.20個のスプライトのいずれかをタッチすると.タッチされたスプライトのタグ値が必要です.
コードで私を助けてください。前もって感謝します。
20個のスプライトを持っています.20個のスプライトすべてがMutableArrayに追加されます.20個のスプライトのいずれかをタッチすると.タッチされたスプライトのタグ値が必要です.
コードで私を助けてください。前もって感謝します。
それはかなり単純なはずです。コードを提供しないので、次のようになります。
for (CCSprite *aSprite in arrayOfSprites){
if ([self screenPosition:touchPosition intersectedWithSprite: aSprite]){
NSInteger tagForSprite = aSprite.tag; // do what you want with this value
}
}
touchPositionIntersectedWithSprite は、実際の衝突をチェックして BOOL を返すメソッドです...
タッチを登録します。使用機能:
-(id) init{
if( (self=[super init])){
self.isTouchEnabled = YES;
/* to do */
}}
- (void) registerWithTouchDispatcher{
/* to do */}
- (BOOL) containsTouchLocation:(UITouch *)touch
{
return YES;
}
関数でスプライトのタッチをキャッチして分析する
- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
//e.g. mArrSprites - your NSMutableArray with 20 sprites
for(CCSprite * sprite in mArrSprites){
if (CGRectContainsPoint(sprite.boundingBox, location)){ //check contains sprite rect your touch
int tag = sprite.tag; //GET tag of sprite
}
}
}