我希望球 Sprite 每次都跳离地面到相同的高度。但是随着每次跳跃,球的最大高度位置都会增加。
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
SKNode *ground = [SKNode node];
ground.physicsBody = [SKPhysicsBody bodyWithEdgeFromPoint:CGPointZero toPoint:CGPointMake(CGRectGetMaxX(self.frame), 0)];
[self addChild:ground];
SKShapeNode *ball = [[SKShapeNode alloc] init];
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddArc(myPath, NULL, 0, 0, 30, 0, M_PI*2, YES);
ball.path = myPath;
ball.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame)-100);
ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];
ball.physicsBody.linearDamping = 0.0;
ball.physicsBody.restitution = 1.0;
[self addChild:ball];
}
return self;
}
有什么建议吗?
最佳答案
看看在两个物体上同时设置恢复和摩擦力,而不仅仅是球。如果它在增长而不是收缩,则物理实体可能存在错误。 SKShapeNode
在我的测试中是出了名的不可靠 - 我会考虑使用 SKSpriteNode
来保持理智。
关于ios - SpriteKit : unexpected physics issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19362404/