views:

165

answers:

1

I have a code that set's a bow's angle according to where you have touched the screen. a simple "bow.rotation = X" command is performed on the ccTouchesMoved event. the problem is, that while running the code on 0.7.1 of cocos2d against 0.9 or 0.8.2 it worked way better, in 0.9 and 0.8.2 it seems like it skippes some of the touchesmove event... what could it be? heres the code...:

-(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL: location];
    if(player.state == StateNotPrepared) {
        if(CGRectContainsPoint(spriteToRect(fireButton), location)) {
            [player prepareShot];
            [powerMeter resetBar];
            [powerMeter startLoadingBar];
        } else {
            float newAngle = [player angleByTouchPoint: location];
            [self setAngles: newAngle];
        }   
    }
    return kEventHandled;
}

-(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL: location];
    if(player.state == StateNotPrepared || player.state == StatePrepared) {
        if( !CGRectContainsPoint(spriteToRect(fireButton), location) ) {
            float newAngle = [player angleByTouchPoint: location];
            [self setAngles: newAngle];
        }   
    }
    return kEventHandled;
}
+1  A: 

This may be related to the type of director used vs. the OS of the device. Try the different directors and see if you get different behavior.

[Director setDirectorType:XXXX];

Where XXXX is one of:

  • CCDirectorTypeNSTimer (default)
  • CCDirectorTypeMainLoop
  • CCDirectorTypeThreadMainLoop
  • CCDirectorTypeDisplayLink

I know that some people have reported issues with the DisplayLink director (though that's generally ideal otherwise when available).

David Whatley
in 0.9 i cant find any method named setDirectorType:[[CCDirector sharedDirector] setDirectorType];no such method
Alon Amir
It's there. You'll even see it used in like TileMapTest.m: [CCDirector setDirectorType:CCDirectorTypeDisplayLink];
David Whatley
You're right, it exists. you have to call setDirector type on the class itlsef, not on the sharedDirector instance, and you have to do it before you do anything else with the sharedDirector.Thanks.
Alon Amir