diff --git a/animate.html b/animate.html new file mode 100644 index 0000000..a16c97d --- /dev/null +++ b/animate.html @@ -0,0 +1,177 @@ + + + How to animate a rocket. + + + + + + + + + + + + + +

Learn how to animate a rocket
in Objective-C using SpriteKit

+ +

Begin by setting up your scene.

+
< +
+					-(id)initWithSize:(CGSize)size {    
+				    if (self = [super initWithSize:size]) {
+				        /* Setup your scene here */
+				        
+				        
+				        
+				        self.backgroundColor = [SKColor colorWithRed:0.05 green:0.05 blue:0.3 alpha:1.0];
+				        self.view.backgroundColor = [UIColor clearColor];
+				        self.view.backgroundColor =  [UIColor colorWithPatternImage:[UIImage imageNamed:@"Spaceship.png"]];
+				        
+				        SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"HelveticaNeue"];
+				        
+				        myLabel.text = @"How To Build A Rocket";
+				        myLabel.fontSize = 15;
+				        myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
+				                                       CGRectGetMidY(self.frame));
+				        
+				        [self addChild:myLabel];
+				    }
+				    return self;
+				}
+
+
+

Now call the nosecone when touch begins.

+
+					-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
+				    /* Called when a touch begins */
+				    
+				    for (UITouch *touch in touches) {
+				        CGPoint location = [touch locationInNode:self];
+				        
+				        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"nosecone"];
+				        
+				        sprite.position = location;
+				        
+				        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
+				        
+				        [sprite runAction:[SKAction repeatActionForever:action]];
+				        
+				        [self addChild:sprite];
+				    }
+				}
+
+

Call the ship when dragging the touch across your screen.

+
+
+					-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
+				    /* Called when a touch moves */
+				    
+				    for (UITouch *touch in touches) {
+				        CGPoint location = [touch locationInNode:self];
+				        
+				        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"spacecraft"];
+				        
+				        sprite.position = location;
+				        
+				        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
+				        
+				        [sprite runAction:[SKAction repeatActionForever:action]];
+				        
+				        [self addChild:sprite];
+				    }
+				}
+
+
+

Finally, call the trunk on touch release.

+
+
+				-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
+				    /* Called when a touch ends */
+				    
+				    for (UITouch *touch in touches) {
+				        CGPoint location = [touch locationInNode:self];
+				        
+				        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"trunk"];
+				        
+				        sprite.position = location;
+				        
+				        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];
+				        
+				        [sprite runAction:[SKAction repeatActionForever:action]];
+				        
+				        [self addChild:sprite];
+				    }
+				}
+
+
+

Now hit Run, and enjoy:

+
+ + + +

The full Obj C repo is available here.

+ +