gpt4 book ai didi

iphone - 使用cocos2d在iPhone游戏中实现3D透视图

转载 作者:行者123 更新时间:2023-12-03 18:38:34 24 4
gpt4 key购买 nike

我正在使用 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];

}*

最佳答案

终于用cocos2d完成了抛纸。我实现了贝塞尔曲线,就是这样,

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

关于iphone - 使用cocos2d在iPhone游戏中实现3D透视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9871732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com