【发布时间】:2014-01-25 20:13:32
【问题描述】:
我正在尝试使用 CCPhysicsNode 为游戏制作一个物理世界(物理将用于子弹碰撞检测)。物理实体的调试图偏离了它们实际所在的位置。我相信这可能是由于有一个 CCNode 作为物理世界的父级,并且 CCNode 跟随玩家精灵(游戏世界大于屏幕)。 以下是相关代码:
_controlLayer = [CCNode node];
_controlLayer.position = ccp(0, 0);
_gameLayer = [CCNode node];
[self addChild:_gameLayer];
[self addChild:_controlLayer];
_physicsWorld = [CCPhysicsNode node];
_physicsWorld.debugDraw=YES;
_physicsWorld.collisionDelegate = self;
[_gameLayer addChild:_physicsWorld];
[self setupMap];
[self setUpControls];
[self setupPlayer];
_allZombies = [[NSMutableArray alloc]init];
[_gameLayer runAction:[CCActionFollow actionWithTarget:_player worldBoundary:_map.boundingBox]];
-(void)setupPlayer {
_player = [CCSprite spriteWithImageNamed:@"Player.png"];
_player.position = CGPointMake(1024/2+60,768/2+60);
_player.anchorPoint = ccp(0.5, 0.5);
_player.physicsBody = [CCPhysicsBody bodyWithRect:_player.boundingBox cornerRadius:0];
_player.physicsBody.elasticity = 0;
_player.physicsBody.sensor=YES;
_player.physicsBody.collisionGroup = @"playerGroup";
_player.physicsBody.collisionType = @"playerCollision";
[_player setScale:0.5];
[_physicsWorld addChild:_player];
}
所以我的问题是,为什么绘制在玩家精灵所在的位置?
【问题讨论】:
标签: ios objective-c cocos2d-iphone game-physics