ios - bodyWithEdgeLoopF​​romRect 不能横向工作

标签 ios iphone objective-c sprite-kit skphysicsbody

我只是想在景观中设置一个基本场景,使用重力,并将场景置于边缘循环中。

我设置了场景的物理体和 mainCharacter Sprite 物理体,这是我的代码:

-(id)initWithSize:(CGSize)size
{
    if (self = [super initWithSize:size])
    {
        self.backgroundColor = [SKColor redColor];
        [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]];
    }
    return self;
}


-(void)setupMain
{
    if (!self.mainCharacter)
    {
        self.mainCharacter = [[SKSpriteNode alloc] initWithImageNamed:@"spriteDefault"];

       [self.mainCharacter setPosition:CGPointMake(CGRectGetMidX([self frame]), CGRectGetMidY([self frame]))];

       [self addChild:self.mainCharacter];

       self.mainCharacter.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.mainCharacter.frame.size];
       self.mainCharacter.physicsBody.dynamic = YES;
       self.mainCharacter.physicsBody.affectedByGravity = YES;
       self.mainCharacter.physicsBody.mass = 0.02;
    }
 }

因此,在纵向模式下,一切都完美无缺,但是,在横向模式下,事情就变得非常棘手了。

我想这与

有关
  [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]];

奇怪的是,横向 x 轴(纵向模式下的 y 轴)的边缘循环工作正常,但我只是穿过 y 轴(纵向 x 轴)。

我的猜测是框架返回 y 轴上某个不在横向模式屏幕范围内的位置……意味着它在屏幕上方或下方的某个位置。 ...也许...不太确定。

但是,我尝试了几种不同的选择,包括自己手动设置矩形 CGRectMake() 函数 我无法让任何东西正常工作。

任何建议将不胜感激!!!

最佳答案

好的,这是一个 super Janky 修复...

 self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(0, 200, 320, 200)];

我不确定为什么会这样......而且它显然会在较小的屏幕尺寸上出现一些问题...更好的修复和解释将不胜感激! 谢谢:D

关于ios - bodyWithEdgeLoopF​​romRect 不能横向工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19580706/

相关文章:

iphone - 没有为 MFMailComposeViewController 调用 didFinishWithResult

ios - 使用 SLRequest 将多张图片上传到 facebook

iphone - 从 iphone 应用程序中获取 html 链接

iphone - 进入后台时如何争取时间完全关闭 UIAlertView?

iphone - 缩放从相机拍摄的风景图像以在人像中使用

ios - 如果我在使用 cocoapods 时必须修复某些东西,如何更改 pod

iphone - UITableViewCell 问题中的自定义 UIView

iphone - 使用 UINavigationController 从右向左推送 ViewController

ios - 堆叠条形图突出显示完整的单个条形图

ios - UICollectionView 图片加载问题