acciones al tocar Movido en cocos2d-iphone

I'm trying to start developing cocos2d games. So, I'm new in cocos2d, but I developed few applications on iPhone. I installed cocos templates (v2.0) and created new project with box2d phisics. Here I can see a demo project with blocks and some menus. When I tap screen, new block appears, and falls to the botton of screen. Than must be implemented here:

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //Add a new body/atlas sprite at the touched location
    for( UITouch *touch in touches ) {
        CGPoint location = [touch locationInView: [touch view]];

        location = [[CCDirector sharedDirector] convertToGL: location];

        [self addNewSpriteAtPosition: location];
    }
}

so, sprite appears when touches ended. But how to do something when touches begun or moved? I cant this finds methods for cocos. I saw some tutorials, there is method like this:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
   return YES;
}

but it never called... What am I doung wrong?

preguntado el 02 de febrero de 12 a las 10:02

2 Respuestas

Implementar

(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

Y asegúrate de tener

self.isTouchEnabled = YES;.

en tu init method for that layer.

Respondido 02 Feb 12, 14:02

If you want to use ccTouchBegan instead of ccTouches you need to add the targeted delegate. See here: cocos2d-iphone.org/forum/topic/8354 - davbryn

Implementar:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
       // whatever is needed here
       return YES;
}

in your cocos2d class (the same implementing ccTouchesEnded), then it will be called.

Respondido 02 Feb 12, 14:02

thx for responce, but as was I say, I tyed it. I put this code with NSLog (@"qwd3"); but no log messages was posted on touch... thats why I asking... - Centinela

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.