gpt4 book ai didi

sprite-kit - 应用角冲量

转载 作者:行者123 更新时间:2023-12-03 08:20:11 25 4
gpt4 key购买 nike

这是我的代码,用于相互影响的球员和球。我想做的就是向球施加力量,就像我的球员正在投篮一样。我希望球能用力离开我的球员。我该如何对此施加冲动或强制。我已经尝试了很多次,但是我是Sprite Kit的新手。

- (void) Player {
_Player = [SKSpriteNode spriteNodeWithImageNamed:@"player1"];
_Player.xScale = 0.09;
_Player.yScale = 0.09;
_Player.position = CGPointMake(self.size.width/4, self.size.height/2);
_Player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_Player.size];
_Player.physicsBody.dynamic = NO;
[self addChild:_Player];
}

- (void) TheMethodForBall {
SKSpriteNode *sprites = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];
sprites.xScale = 0.19;
sprites.yScale = 0.19;
sprites.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprites.size];
sprites.physicsBody.dynamic = YES;
sprites.physicsBody.affectedByGravity = NO;
sprites.physicsBody.allowsRotation = YES;
sprites.physicsBody.restitution = YES;
sprites.physicsBody.angularVelocity = 4;
sprites.physicsBody.usesPreciseCollisionDetection = YES;
[self addChild:sprites];
}

最佳答案

我想您想施加像踢一样的冲动吗?

您需要以下内容,也许当您触摸屏幕/或按钮时

[_myBall.physicsBody applyImpulse:CGVectorMake(somePowerX, somePowerY)];

这是另一个 post,它将帮助您入门

另外,这对于初学者来说是一个很好的 tutorial

关于sprite-kit - 应用角冲量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22890838/

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