小编Hir*_*ren的帖子

cocos2d和box2d:精灵触摸不正常

我添加了7个精灵并给它们标记和zorder ..但我无法触及第三个对象,最后只剩下一个物体然后我触摸它..但是当我添加6个精灵时我会得到触摸得当.所有的精灵位置是相同的,但zorder是不同的..我无法理解什么是问题..我已经使用查询回调类来获取触摸..这里我添加了一些我的代码..

添加精灵的代码..

 zIndex = 7;

            for(int i = 0; i<zIndex; i++)
            {
                CCSprite *paddle = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%d.png",i+1]];
                paddle.position = ccp(winSize.width/2, winSize.height/2);
                [self addChild:paddle z:zIndex-i tag:i+1];
                [mutArrSprites addObject:paddle];
                NSLog(@"Z = %d tag = %d ",zIndex-i , i+1);
            }

            for(CCSprite *sprite in mutArrSprites)
            {
                [self addUserDataToNode:sprite];
            }       
Run Code Online (Sandbox Code Playgroud)

在touchbegan方法

if (_mouseJoint != NULL) return;

UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);

// Make a small box.
b2AABB …
Run Code Online (Sandbox Code Playgroud)

iphone touch cocos2d-iphone box2d-iphone ccsprite

6
推荐指数
1
解决办法
625
查看次数

标签 统计

box2d-iphone ×1

ccsprite ×1

cocos2d-iphone ×1

iphone ×1

touch ×1