我似乎无法弄清楚为什么出现了错误的访问代码,有人可以帮忙吗?
我有代码添加一个精灵和一个发射器节点,每个节点都有自己的物理体。现在,精灵在地图上移动,并且有一个跟随它的摄像头。精灵的父亲是myWorld
,它本身就是场景的孩子。当我尝试在移动的精灵(初始化关节时没有移动)之间添加一个physicsJoint时,我得到一个糟糕的访问代码。这是代码:
self.sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
self.sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self.sprite setScale:.5];
self.sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.sprite.size];
self.sprite.physicsBody.mass = 50;
self.sprite.physicsBody.affectedByGravity = NO;
self.sprite.name = @"sprite";
self.sprite.zPosition = 5;
self.sprite.physicsBody.velocity = CGVectorMake(300, 0);
self.sprite.physicsBody.categoryBitMask = plane;
self.sprite.physicsBody.collisionBitMask = ships;
self.sprite.physicsBody.affectedByGravity = YES;
NSString *firePath = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
self.smokeTrail = [SKEmitterNode node];
self.smokeTrail = [NSKeyedUnarchiver unarchiveObjectWithFile:firePath];
self.smokeTrail.position = CGPointMake(self.sprite.position.x-2*self.sprite.size.width/5, self.sprite.position.y);
[self.smokeTrail setScale:1];
self.smokeTrail.zPosition = self.sprite.zPosition-1;
self.smokeTrail.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.smokeTrail.frame.size];
self.smokeTrail.physicsBody.dynamic = YES;
self.smokeTrail.physicsBody.affectedByGravity = NO;
self.smokeTrail.physicsBody.categoryBitMask = 0;
smokeJoint = [SKPhysicsJointFixed jointWithBodyA:self.sprite.physicsBody bodyB:self.smokeTrail.physicsBody anchor:CGPointMake(self.smokeTrail.position.x+self.smokeTrail.frame.size.width/2,self.smokeTrail.position.y)];
...
[myWorld setScale:0.4f];
self.sprite.physicsBody.velocity = CGVectorMake(0, 0);
[self addChild:myWorld];
[self addChild:backgroundNode];
[self addChild:buttonDown];
[self addChild:buttonUp];
[myWorld addChild:blueBox];
[self addChild:self.speed];
[self addChild:self.altitude];
[self addChild:self.darkBlueWave];
[self addChild:self.lightBlueWave];
[myWorld addChild:self.smokeTrail];
[myWorld addChild:self.sprite];
[myWorld addChild:randomNode];
[myWorld addChild:camera];
[self.physicsWorld addJoint:smokeJoint]; // Bad Access Code Happens Here