IOS 8 sprite set collides with top and bottom, but not with sides?

I made it a simple effect of hitting the ball on the screen, it only works with the top and bottom edges of idk, why, besides, when I try to use this code in the iOS 7 sprite set template in the initwithsize method, it works is this an error or something still? //

#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
+4
source share
2 answers
  1. You did not install the binding node, which is very important, set it to CGPointMake (0.5,0.5)

  2. The gravity vector must be set to (0, -9.8), but it also (0,0) changes it.

Now your problem

(0.5,0.5) angular , (), , .

(0.5,0.5), , , , . .

ios7 , , , , .

+2

, , (0,5,0,5).

, - . . NSLog , .

+1

Source: https://habr.com/ru/post/1606231/


All Articles