我是SpriteKit的新手,我制作了简单的测试游戏,我遇到了碰撞对象的问题。
玩家必须与墙碰撞。目前玩家通过墙壁移动。以下是代码示例:
设置播放器:
SKSpriteNode *player = [SKSpriteNode spriteNodeWithImageNamed:@"player"];
player.name = playerCategoryName;
player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:player.frame.size];
player.physicsBody.restitution = 0.1f;
player.physicsBody.friction = 0.0f;
player.physicsBody.dynamic = NO;
player.physicsBody.categoryBitMask = CollisionTypePlayer;
player.physicsBody.collisionBitMask = CollisionTypeNet ;
player.physicsBody.contactTestBitMask = CollisionTypeWall;
设置网络:
SKSpriteNode *wall = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(20, 350)];
wall.position = CGPointMake(CGRectGetMidX(self.frame), self.wall.frame.size.height * 0.6);
wall.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
wall.physicsBody.dynamic = NO;
wall.physicsBody.categoryBitMask = CollisionTypeWall;
wall.physicsBody.contactTestBitMask = 0;
wall.physicsBody.collisionBitMask = CollisionTypePlayer;
[self addChild:wall];
任何帮助将不胜感激!