0

I am trying move nodes to a set X distance using an SKAction with the same duration. The Nodes are in different X positions so the speed of how the node moves is different, is there a way to make the speed the same without affecting the positioning of the nodes?

Example.

-(void)beginningGamePlatforms {

SKSpriteNode *beginningPlatform = [SKSpriteNode spriteNodeWithImageNamed:@"PlatformBeginning"];
beginningPlatform.zPosition = 2;
beginningPlatform.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:beginningPlatform.size];
beginningPlatform.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
beginningPlatform.position = CGPointMake(beginningPlatform.position.x - 20, beginningPlatform.position.y - 129);
beginningPlatform.physicsBody.dynamic = NO;

SKSpriteNode *platformSpawn1 = [SKSpriteNode spriteNodeWithImageNamed:@"platformSpawn1"];
platformSpawn1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:platformSpawn1.size];
platformSpawn1.position = CGPointMake(beginningPlatform.position.x, CGRectGetMidY(self.frame));
platformSpawn1.position = CGPointMake(platformSpawn1.position.x + 196, platformSpawn1.position.y - 129);
platformSpawn1.physicsBody.dynamic = NO;

SKSpriteNode *platformSpawn2 = [SKSpriteNode spriteNodeWithImageNamed:@"platformSpawn1"];
platformSpawn2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:platformSpawn2.size];
platformSpawn2.position = CGPointMake(platformSpawn1.position.x,CGRectGetMidY(self.frame));
platformSpawn2.position = CGPointMake(platformSpawn2.position.x + 196, platformSpawn2.position.y - 129);
platformSpawn2.physicsBody.dynamic = NO;

SKAction *moveLeft = [SKAction moveTo:CGPointMake(-100 , beginningPlatform.position.y) duration:9];
SKAction *removeFromParent = [SKAction removeFromParent];

SKAction *AllTwo = [SKAction sequence:@[moveLeft,removeFromParent]];

[self addChild:beginningPlatform];

[self addChild:platformSpawn1];

[self addChild:platformSpawn2];

[beginningPlatform runAction:AllTwo];

[platformSpawn1 runAction:AllTwo];

[platformSpawn2 runAction:AllTwo];

}

In my code I created 3 platforms with a set distance within each other that when the sprite images combined, it creates the illusion of a single wide platform. However when running the actions, the illusion breaks. Any information will be appreciated.

Blank
  • 113
  • 9
  • 1
    basic calculation: distance / speed = duration ... distance is length of vector: (node.position - node.target). Speed is an arbitrary value you choose. – CodeSmile Aug 01 '14 at 17:52
  • possible duplicate of [How do you move an IOS SKSprite at a consistent speed](http://stackoverflow.com/questions/19105631/how-do-you-move-an-ios-sksprite-at-a-consistent-speed) – CodeSmile Aug 01 '14 at 17:53
  • You are setting the position of each node twice. You will need multiple actions to move the nodes at the same speed from different positions. – 0x141E Aug 01 '14 at 17:55

1 Answers1

0

You can try replacing the moveTo: in:

SKAction *moveLeft = [SKAction moveTo:CGPointMake(-100 , beginningPlatform.position.y) duration:9];

with a moveBy: varient. Currently, the different platforms start at different positions to make the illusion of a continuous platform, but by moving all of them to the same place, they won't maintain their original position intervals.

Jackson
  • 559
  • 7
  • 20
  • Thanks for the advice, but originally, moving them by -100 meant moving them offscreen, and I now have used the update method to update their positions and then when it hits a invisible line "node" it gets removed. – Blank Aug 07 '14 at 21:14