2014-10-17 63 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