sprite kit - Emitted particles follow parent node -
i setting sknode
follows:
- (id)init { self = [super init]; if (self) { sktextureatlas *atlas = [sktextureatlas atlasnamed:@"sprites"]; skspritenode *spritenode = [skspritenode spritenodewithtexture:[atlas texturenamed:@"cat"]]; [self addchild:spritenode]; // create particle trail skemitternode *emitternode = [nskeyedunarchiver unarchiveobjectwithfile:[[nsbundle mainbundle] pathforresource:@"hearts" oftype:@"sks"]]; emitternode.position = cgpointmake(0, 20); [self insertchild:emitternode atindex:0]; // setting physics self.physicsbody = [skphysicsbody bodywithrectangleofsize:spritenode.frame.size]; self.physicsbody.dynamic = yes; self.physicsbody.affectedbygravity = no; } homecoming self; }
when node moves around horizontally along x-axis, source of particle trail moves along it, expected. not expected emitted particles well, when instead expect them move straight along y-axis original x position.
is there way prevent behaviour?
creation (in scene):
spaplayer *player = [[spaplayer alloc] init]; player.position = cgpointmake(cgrectgetmidx(self.frame), cgrectgetmidy(self.frame)); [self addchild:player];
movement code:
[node.physicsbody applyforce:cgvectormake(20 * data.acceleration.x, 0)];
image reference:
make emitter kid of sprite (as have).
to create particles move independently player node is, assign skemitternode's targetnode property, preferably assign scene in:
// sure self.scene isn't still nil when this, instance in node's init emitter.targetnode = self.scene;
this spawn particles @ player sprite position won't travel along it.
sprite-kit
No comments:
Post a Comment