2012-03-26 22 views
7

estoy desarrollando 'Paper Toss' para el iphone usando cocos2d & me gustaría saber que la forma de aplicar 3D vista en perspectiva en esto, porque mientras estamos tirando la bola de papel en la bandeja, tenemos para obtener el feel.I'am 3D adjuntando el código que he hecho, el uso de este tengo una línea recta motion.Please ayudarme ..vista en perspectiva 3D en el juego iphone usando cocos2d

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

// Choose one of the touches to work with 
UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInView:[touch view]]; 
location = [[CCDirector sharedDirector] convertToGL:location]; 

// Set up initial location of projectile 
CGSize winSize = [[CCDirector sharedDirector] winSize]; 
CCSprite *projectile = [CCSprite spriteWithFile:@"ball.png" 
              rect:CGRectMake(0, 0, 40, 40)]; 
projectile.position = ccp(winSize.width/2,20); 

// Determine offset of location to projectile 
int offX = location.x - projectile.position.x; 
int offY = location.y - projectile.position.y; 

// Bail out if we are shooting down or backwards 
if (offY <= 0) return; 

// Ok to add now - we've double checked position 
[self addChild:projectile]; 

// Determine where we wish to shoot the projectile to 
int realY = winSize.height + (projectile.contentSize.width/2); 
float ratio = (float) offX/(float) offY; 
int realX = (realY * ratio) + projectile.position.x; 
CGPoint realDest = ccp(realX, realY); 

// Determine the length of how far we're shooting 
int offRealX = realX + projectile.position.x; 
int offRealY = realY + projectile.position.y; 
float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY)); 
float velocity = 480/1; // 480pixels/1sec 
float realMoveDuration = length/velocity; 

// Move projectile to actual endpoint 
[projectile runAction:[CCSequence actions: 
         [CCMoveTo actionWithDuration:realMoveDuration position:realDest], 
         [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], 
         nil]]; 
//add to the projectiles array 
projectile.tag = 2; 
[_projectiles addObject:projectile]; 

} *

Respuesta

7

Finalmente he terminado lanzamiento de papel utilizando cocos2d.I implementado curva de Bezier y aquí está,

// Bezier curve control points 
    bezier.controlPoint_1 = ccp(location.x-CONTROL_POINT1_X, CONTROL_POINT1_Y); 
    bezier.controlPoint_2 = ccp(location.x-CONTROL_POINT2_X, CONTROL_POINT2_Y); 
    bezier.endPosition = ccp(location.x-CONTROL_POINT1_X,distance); 

    // Motion along bezier curve and finally call a function 
    [projectile runAction:[CCSequence actions: 
          [CCAutoBezier actionWithDuration:DEFAULT_ACTION_DURATION bezier:bezier], 
          [CCCallFuncN actionWithTarget:self selector:@selector(collisionCheck:)], nil]]; 
+5

He añadido un ventilador en 3 niveles y ahora mi juego luks genial :) –

+0

¿Puede decirme más acerca de CONTROL_POINT – Muniraj

+0

@TonyMac: - Podemos usar la curva de Bezier para el tipo de movimiento de proyectil. Pero en el papeleo, había visto que el tamaño del papel también varía. Como haces eso ? también ¿puedes decirme cómo podemos implementar el efecto rebote cuando el papel colisiona con los bordes del cubo de basura? gracias – Tornado

3

Sólo la escala de su imagen de sprites por lo que se hace más pequeño cuanto más "lejos" está.

+2

sí, escalado debe ser done.But no lo puedo dar la vista exacta perspectiva .. –

+0

¿Qué quiere decir por la "visión exacta perspectiva"? –

1

Hey puede utilizar para bezier curve3d vista en perspectiva en cocos2d.

bezier.controlPoint_1 = ccp(location.x-CONTROL_POINT1_X, CONTROL_POINT1_Y); 
    bezier.controlPoint_2 = ccp(location.x-CONTROL_POINT2_X, CONTROL_POINT2_Y); 
Cuestiones relacionadas