Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

I don't have idea how to do it

Hello,

I try to move this block up and down. At the moment it viewed as horizontally but how do i make it go up and down? not horizontalli?

#import "MyScene.h"

@implementation MyScene

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */

        self.backgroundColor = [SKColor colorWithRed:0.29 green:0.75 blue:.99 alpha:1];

        // create platform (just a colored aprite)
        SKSpriteNode *platform = [SKSpriteNode spriteNodeWithColor:[SKColor brownColor] size:CGSizeMake(100, 20)];
        platform.position = CGPointMake(50, 100);
        [self addChild:platform];

        // create the two actions
        SKAction *move = [SKAction moveByX:(size.width-platform.size.width) y:0 duration:2];
        SKAction *moveBack = [move reversedAction];
        // just wait
        SKAction *wait = [SKAction waitForDuration:0];

        // now sequence them
        SKAction *backAndForth = [SKAction sequence:@[move,wait,moveBack,wait]];

        SKAction *repeater = [SKAction repeatActionForever:backAndForth];

        // run it
        [platform runAction:repeater];



           }
    return self;
}


-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
}

@end

1 Answer

Your SKAction is set so that the sprite is movingX but not movingY In order to move up and down, you have to make it so the sprite changes by Y. For example

SKAction *move = [SKAction moveByX:0 y:(size.width-platform.size.width) duration:2];

Try this and see if it moves vertically now.