首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SKEmitterNode targetNode路径跟踪反转

SKEmitterNode targetNode路径跟踪反转
EN

Stack Overflow用户
提问于 2015-12-09 08:27:38
回答 1查看 57关注 0票数 1

我创建了一个SKEmitterNoder (标准Fire.sks模板)&将它添加到一个名为SKSpriteNode的SKSpriteNode中。问题是,我通过教程学习了iOS游戏的教程&他们教我创建平铺地图的方法,本质上是将它们翻转到init上,这样(0,0)就会出现在屏幕的左下角,而不是左上角。我认为这影响了我的SKEmitterNode targetNode属性,因为当球在场景中移动时,发射节点就会向相反的方向移动。谁能告诉我该怎么做才能改变这一切?我不能改变世界参数,所以我需要一些东西来改变SKEmitterNode的轨迹,这样它才能正确地跟随球节点。以下是我的当前代码:

代码语言:javascript
复制
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)坐标。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-10 19:04:07

我的一个朋友找到了解决这个问题的办法。我在这里张贴它,以防有人也有一个倒置的贴图,其中(0,0)坐标在场景的左下角。

代码语言:javascript
复制
    //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.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34173993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档