-1

20個のスプライトを持っています.20個のスプライトすべてがMutableArrayに追加されます.20個のスプライトのいずれかをタッチすると.タッチされたスプライトのタグ値が必要です.

コードで私を助けてください。前もって感謝します。

4

2 に答える 2

0

それはかなり単純なはずです。コードを提供しないので、次のようになります。

for (CCSprite *aSprite in arrayOfSprites){
    if ([self screenPosition:touchPosition intersectedWithSprite: aSprite]){
        NSInteger tagForSprite = aSprite.tag; // do what you want with this value
    }
}

touchPositionIntersectedWithSprite は、実際の衝突をチェックして BOOL を返すメソッドです...

于 2013-01-30T08:26:06.627 に答える
0
  1. タッチを登録します。使用機能:

    -(id) init{
    if( (self=[super init])){
        self.isTouchEnabled = YES;
        /* to do */
    }}
    
    - (void) registerWithTouchDispatcher{
    /* to do */}
    
    - (BOOL) containsTouchLocation:(UITouch *)touch
    {
        return YES;
    }
    
  2. 関数でスプライトのタッチをキャッチして分析する

    - (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
            }
        }
    }
    
于 2013-01-30T09:03:08.047 に答える