I made this simple effect of a ball bouncing off the screen. It only works with the top and bottom edges but I don't know why. Besides, when I try this code in an iOS 7 SpriteKit
template in the initwithsize
method it works. Is this a bug or something?
#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