cómo mover el objeto en ubicaciones específicas.cómo mover el objeto en ubicaciones específicas en cocos2d
por ejemplos. tengo una barra pequeña (ancho = 50, altura = 10). Tengo que mover esto como un émbolo manualmente. Quiero mover solo en x cordinates (los límites son x = 20 (punto de inicio) a x = 50 (punto final)) sin movimientos en las coordenadas y. pero se mueve 50 a 10 después de que no se mueve. codificación: -
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (isPlaying) {
UITouch *touch = [[event allTouches] anyObject];
touchPosition = [touch locationInView:touch.view];
if (CGRectContainsPoint(para3.boundingBox,touchPoint)
isDragging = YES;
touchOffset = para3.position.y - touchPosition.y;
}
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (isPlaying) {
UITouch *touch3 = [[event allTouches] anyObject];
float distanceMoved =
([touch3 locationInView:touch3.view].y + touchOffset) -
para3.position.y;
float newY = para3.position.y + distanceMoved;
if (newY > 67 && newY < 99)
para3.position = CGPointMake(newY , para3.position.y );
//para3.contentSize/2
if (newY >67)
para3.position = CGPointMake(67, para3.position.y);
if (newY < 99)
para3.position = CGPointMake(99, para3.position.y);
}
}
Tienes que buscar los diferentes sistemas de coordenadas de Cocos y UIView. Entonces necesita convertir el punto de locationInView. No recuerdo exactamente. Pero CCDirector es la clase que implementa estos métodos. ;-) Espero que esto haya ayudado. –
para3.position = cpp (x, y); Tienes que usar cpp (x, y); en lugar de CGPointMake (x, y); usando cocos2d – 0xDE4E15B
mi error, ccp (x, y); – 0xDE4E15B