使用cocos2d在iphone游戏中显示3D透视图

使用cocos2d在iphone游戏中显示3D透视图,iphone,cocos2d-iphone,Iphone,Cocos2d Iphone,我正在使用cocos2d为iphone开发“Paper-Toss”&我想知道如何实现3D透视图,因为当我们将纸球扔进垃圾箱时,我们必须获得3D的感觉。我正在附加我已经完成的代码,用这个我得到了一个直线运动,请帮帮我 *- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // Choose one of the touches to work with UITouch *touch = [touches any

我正在使用cocos2d为iphone开发“
Paper-Toss”
&我想知道如何实现
3D
透视图,因为当我们将纸球扔进垃圾箱时,我们必须获得
3D
的感觉。我正在附加我已经完成的代码,用这个我得到了一个直线运动,请帮帮我

*- (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];
*-(void)cctouchesend:(NSSet*)接触事件:(UIEvent*)事件{
//选择要使用的触摸之一
UITouch*touch=[触摸任何对象];
CGPoint location=[touch locationInView:[touch view]];
location=[[CCDirector sharedDirector]convertToGL:location];
//设置投射物的初始位置
CGSize winSize=[[CCDirector sharedDirector]winSize];
CCSprite*投射物=[CCSprite spriteWithFile:@“ball.png”
rect:CGRectMake(0,0,40,40)];
射弹位置=ccp(winSize.宽度/2,20);
//确定位置对射弹的偏移量
int offX=位置.x-投射物.position.x;
int offY=位置.y-投射物.position.y;
//如果我们正在向下射击或向后射击,请救出

如果(offY只需缩放您的精灵图像,使其变小,即“离得越远”。

最后,我使用cocos2d完成了抛纸。我实现了bezier曲线,它就在这里

  // 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]];

嘿,您可以在
cocos2d
中使用
bezier曲线
来查看
3d
透视图

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

你说的“精确透视图”是什么意思?我在3个关卡中添加了一个粉丝,现在我的游戏很棒:)你能告诉我更多关于控制的情况吗_POINT@TonyMac:-我们可以使用贝塞尔曲线进行投射类运动。但在抛纸过程中,我看到纸张的大小也不同。你是如何做到的?你能告诉我当纸张碰撞垃圾箱边缘时,我们如何实现反弹效果吗?谢谢你,请解释一下控制点 ?