1
我試圖在我的場景上創建一個播放器節點。但是圖片「player.png」並不適合物理實體。他們都是獨立的。 PhysicsBody在地面上,圖像漂浮在空中。我的代碼有什麼問題?我如何讓他們在一起?圖像不適合SKSpriteNode幀
#import "Player.h"
@implementation Player
- (instancetype)init {
self = [super initWithImageNamed:@"player.png"];
self.name = @"player";
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(50, 50)];
self.physicsBody.dynamic = YES;
self.physicsBody.allowsRotation = NO;
self.physicsBody.affectedByGravity = YES;
self.zPosition = 100;
self.anchorPoint = CGPointMake(0.5, 0);
return self;
}
@end
// myScene.h
-(void)createSceneContents {
self.currentBackground = [Background generateBackground];
[self addChild: self.currentBackground];
self.physicsWorld.gravity = CGVectorMake(0, _gravity);
self.physicsWorld.contactDelegate = self;
Player *player = [[Player alloc]init];
player.position = CGPointMake([UIScreen mainScreen].applicationFrame.size.width/2, 50);
[self addChild:player];
}