大家好我想知道在两个精灵之间绘制粒子系统线的最佳方法是什么(如果精灵位置移动轻推/重力等则会更新)
我试过这种方式(抱歉我的新手代码><) 从obj01开始画线 - 以obj02结尾 到目前为止工作但我不知道如果精灵移动例如
如何更新线坐标另一个相关的问题可能是因为没有更新pathToDraw,粒子系统似乎已经偏离了 所以我知道我需要更新它(如果有人可以写一个sudo代码/想法,我希望在哪里开始绘制路径,在哪里删除等,这对确定非常有帮助)
感谢N:)
-(void)drawLineFromObj2:(EnemyClass*)obj03 to:(EnemyClass*)obj04
{
if (UFO02IsDead == NO && UFO03IsDead == NO)
{
if (ufo_02ReadyToLink == YES && ufo_03ReadyToLink == YES) {
NSLog(@"Line from Obj2 to obj03");
// **CreateLine**
lineNode02.path = pathToDraw;
lineNode02 = [SKShapeNode node];
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, obj03.position.x, obj03.position.y);
CGPathAddLineToPoint(pathToDraw, NULL, obj04.position.x, obj04.position.y);
lineNode02.path = pathToDraw;
//Add Particles
NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"ForceField" ofType:@"sks"];
SKEmitterNode *myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
[self addChild:myParticle];
//get particles to drop by adding physics?
(this no effect the particles don't follow the line and don't seem
附加到它上面,如果精灵移动,它们也会改变位置)
//myParticle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
//myParticle.physicsBody.affectedByGravity = YES;
//myParticle.physicsBody.allowsRotation = NO;
pathToDraw myParticle使用SKAction followPath:pathToDraw
如何更新pathToDraw以绘制平滑线条并正确删除最后一行
SKAction *followTrack =
[SKAction followPath:pathToDraw asOffset:NO orientToPath:YES duration:.5];
SKAction *forever = [SKAction repeatActionForever:followTrack];
myParticle.particleAction = forever;
lineNode02.name = @"lineNode";
[self addChild:lineNode02];
//is there a way to link the movement with the crystal positions and animate the line length and angle (is there another way of doing this)
//stops line being redrawn (but how to update when sprite is moved, and how to delete the old lines?)
ufo_03ReadyToLink = NO;
}
}
}
答案 0 :(得分:1)
通过将功能向下移动来修复它 - (无效)更新
创建了一个操作块
SKAction *remove = [SKAction removeFromParent];
SKAction* blockAction = [SKAction runBlock:^
{
[self DrawLine]; //draws new line every update
//then removes line
}];
[self runAction:[SKAction sequence:@[blockAction,remove]]];
也使用了纹理而不是粒子,但这就是我附加它的方式
//Add Particles
NSString *myParticlePath =
[[NSBundle mainBundle] pathForResource:@"ForceField" ofType:@"sks"];
myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
[self addChild:myParticle];
SKAction *followTrack =
[SKAction followPath:pathToDraw asOffset:NO orientToPath:YES duration:.5];
SKAction *forever = [SKAction repeatActionForever:followTrack];
myParticle.particleAction = forever;
lineNode01.name = @"lineNode";
[self addChild:lineNode01];
希望它可以帮助别人:)