gpt4 book ai didi

ios - 与顶部和底部碰撞但不与侧面碰撞? (iOS 8)

转载 作者:可可西里 更新时间:2023-11-01 05:40:35 26 4
gpt4 key购买 nike

我制作了一个球从屏幕上弹起的简单效果。它只适用于顶部和底部边缘,但我不知道为什么。此外,当我在 iOS 7 SpriteKit 模板中的 initwithsize 方法中尝试这段代码时,它起作用了。这是错误还是什么?

#import "GameScene.h"

@implementation GameScene

-(void)didMoveToView:(SKView *)view {
self.backgroundColor = [SKColor whiteColor];
SKSpriteNode *ball =[SKSpriteNode spriteNodeWithImageNamed:@"ball"];
ball.position =CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsWorld.gravity = CGVectorMake(0, 0);
CGVector impulse = CGVectorMake(20,20);
[self addChild:ball];

[ball.physicsBody applyImpulse: impulse];

ball.physicsBody.restitution = 1;
ball.physicsBody.friction = 0;
ball.physicsBody.linearDamping = 0;

/*
SKSpriteNode *wall =[SKSpriteNode spriteNodeWithImageNamed:@"wall"];

SKSpriteNode *bar =[SKSpriteNode spriteNodeWithImageNamed:@"bar"];

wall.position= CGPointMake(self.frame.size.width/2, 103);
bar.position = CGPointMake(self.frame.size.width/2, (wall.frame.size.height));
[self addChild:wall];
[self addChild:bar];

*/

}

-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}

@end

最佳答案

Rassam 所说的 anchor 不准确,默认位置在 (0.5,0.5)。

很明显,这与场景的大小有关。您的场景比屏幕宽。 NSLog 场景的宽度来检验我的假设。

关于ios - 与顶部和底部碰撞但不与侧面碰撞? (iOS 8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32436418/

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