2014-10-17 58 views
1

因此,在IOS游戏教程之后,它的IO7并不多于8。物理边缘IOS8,雪碧套件

下面的代码应该是一球蹦跳着,但只有反弹在屏幕的顶部和底部,如果它击中侧边球进入屏幕

#import "GameScene.h" 

@implementation GameScene 

-(void)didMoveToView:(SKView *)view { 
    /* Setup your scene here */ 

self.backgroundColor =[SKColor whiteColor]; 
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; 
self.physicsWorld.gravity = CGVectorMake(0, 0); 

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

ball.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)); 

ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2]; 

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


[self addChild:ball]; 

CGVector myVector = CGVectorMake(0, 5); 
[ball.physicsBody applyImpulse:myVector]; 
} 



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

@end 

必须有东西简单的在这里,但我似乎无法找到在堆栈溢出

回答

1

使用的NSLog的答案,检查您的视图的大小:NSLog(@"%f,%f",self.size.width,self.size.height);

没有与SpriteKit引起视图尺寸为关闭一个什么样的问题你的期望。如果这是您的情况,请确保将视图大小更改为正确的大小:

-(void)didMoveToView:(SKView *)view { 
/* Setup your scene here */ 

self.size = self.view.frame.size; 
self.backgroundColor =[SKColor whiteColor]; 
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; 
self.physicsWorld.gravity = CGVectorMake(0, 0); 

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

ball.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)); 

ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2]; 

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


[self addChild:ball]; 

CGVector myVector = CGVectorMake(50, 20); 
[ball.physicsBody applyImpulse:myVector]; 
} 



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

非常感谢! – user2389087 2014-10-20 08:08:04

+0

没问题,祝你好运! – Andriko13 2014-10-26 01:42:16