我创建了一个SKEmitterNoder (标准Fire.sks模板)&将它添加到一个名为SKSpriteNode的SKSpriteNode中。问题是,我通过教程学习了iOS游戏的教程&他们教我创建平铺地图的方法,本质上是将它们翻转到init上,这样(0,0)就会出现在屏幕的左下角,而不是左上角。我认为这影响了我的SKEmitterNode targetNode属性,因为当球在场景中移动时,发射节点就会向相反的方向移动。谁能告诉我该怎么做才能改变这一切?我不能改变世界参数,所以我需要一些东西来改变SKEmitterNode的轨迹,这样它才能正确地跟随球节点。以下是我的当前代码:
NPCBall *ball = [[NPCBall alloc] initWithBallType:BallTypeRed andName:@"Ball Red"];
ball.position = CGPointMake(x + w/2, y + h/2);
ball.zPosition = -104.0;
[_entityNode addChild:ball];
//Create a random Vector.dx & dy for the NPC. This will apply a random impulse to kick start NPC non-stop movement.
[ball.physicsBody applyImpulse:CGVectorMake([self randomVectorGeneration].dx, [self randomVectorGeneration].dy)];
//Create a particle for the ball (fire).
SKEmitterNode *emitFire = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"Particle_Fire" ofType:@"sks"]];
emitFire.position = CGPointMake(ball.position.x, ball.position.y);
emitFire.targetNode = ball;
[_entityNode addChild:emitFire];P.S. _entityNode是一个SKNode,它加上了球和SKEmitterNode火。这反过来又是一个名为SKNode的_worldNode的子代。_worldNode是自我的子代(这是SKScene)。这个_worldNode是从左下角开始的(0,0)坐标。
发布于 2015-12-10 19:04:07
我的一个朋友找到了解决这个问题的办法。我在这里张贴它,以防有人也有一个倒置的贴图,其中(0,0)坐标在场景的左下角。
//Create a ball sprite.
SKSpriteNode *ball = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(20, 20)];
ball.position = CGPointMake(_worldNode.frame.size.width/2, _worldNode.frame.size.height/2);
[_entityNode addChild:ball]; //<--_entityNode is also an SKNode. It's a child of _worldNode.
ball.zPosition = -104.0;
//Create a random Vector.dx & dy for the NPC. This will apply a random impulse to kick start NPC non-stop movement.
[ball.physicsBody applyImpulse:CGVectorMake([self randomVectorGeneration].dx, [self randomVectorGeneration].dy)];
//Create a particle effect for the ball.
SKEmitterNode *emitFire = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"Particle_Fire" ofType:@"sks"]];
emitFire.name = @"Fire Emitter";
emitFire.targetNode = _worldNode; //<-- This is the demon. Make the emitter follow this SKNode since it moves when the ball moves. Everything in my game is a child of _worldNode.
[ball addChild:emitFire]; //Add the emitter to the ball.https://stackoverflow.com/questions/34173993
复制相似问题