开发者

Multitouch don't work in cocos2d

This is my ccTouchesMoved method. Whats wrong? I use cocos2d framework.

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

CCNode *sprite = [self getChildByTag:kTagPlayer];
CCNode *sprite2 = [self getChildByTag:kTagEnemy];

CGPoint point;

//Собрать все касания.
NSSet *allTouches = [event allTouches];

for (UITouch *touch in allTouches)
{
    point = [touch locationInView:[touch view]];
    point = [[CCDirector sharedDirector] convertToGL:point];

    if (point.y > 384)
    {
        if (point.x > 992)
            sprite2.position = ccp(992, size.height - 100);
        else if (point.x < 32)
            sprite2.position = ccp(32, size.height - 100);
        else
            sprite2.position = ccp(point.x, size.height - 100);
    }
    else
    {
        if (point.x > 992)
            sprite.position = ccp(992, 100);
        else if (point.x < 32)
            sprite.position = ccp(32, 100);
        else
            sprite.position = ccp(point.x, 100开发者_Python百科);
    }
} 

}


Have you enabled multiple touches in your glView? By default the glView is instantiated in the app delegate. The code is below.

[glView setMultipleTouchEnabled:YES];


In case you're developing a Retina display App, be aware that all coordinates are in points, not pixels. So even on a Retina display with 960x640 pixels the coordinates in points (your touch location) will be in the range 480x320.

If you want to use pixels, use the "InPixels" version of all coordinates, in this case:

sprite.positionInPixels = ccp(992, 100);

If that's not the problem you should add to your post what the expected outcome is and what happens instead. A little context goes a long way.


What does the debugger say is in allTouches? You could try getting all the touches for the view like this instead:

UITouch* touch = [touches anyObject];
NSSet* allTouches = [touches setByAddingObjectsFromSet:[event touchesForView:[touch view]]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜