Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to animate a rocket using Objective-C and SpriteKit #4

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions animate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<html>
<head>
<title>How to animate a rocket.</title>


<style>
#container {
border: 2px solid #999999;
width: 500px;
padding: 50px;
}

#first {
border: 2px solid #999999;
width: 50%;
height: 25px;

}

#second {
color:gray;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;padding-top:5px;text-align:center;
position: relative;

}

#third {
border: 0px solid #999999;
position: fixed;
top: 10px;
left: 10px;
color:gray;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:8px;padding-top:8px;

}

.mine {
color: #ff0000;
}

body {
left-margin: 0px;
left-padding: 0px;
}

</style>

<!--updated stylesheet-->
<link href='http://fonts.googleapis.com/css?family=Lusitana' rel='stylesheet' type='text/css'>
<style>
body {background-color:white;margin-left:auto;margin-right:auto;width:100%;}
h1 {color:gray;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:50px;margin-left:auto;margin-right:auto;width:100%;text-align:center;}
h2 {color:gray;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;padding-top:80px;text-align:center;}
.mystyle {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}
.mystyle1 {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}
.mystyle2 {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}
.mystyle3 {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}
.mystyle4 {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}
.mystyle5 {text-decoration: line-through;color:red !important;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:35px;margin-left:auto;margin-right:auto;width:100%;text-align:center;
}

h3 {color:gray;font-family: "Lusitana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica; font-weight: 100; font-size:25px;margin-left:auto;margin-right:auto;width:100%;margin-top:25px;text-align:center;}
p {color:gray;margin-left:auto;margin-right:auto;width:100%;text-align:center;}
img {width:100%;text-align:center;margin-left:auto;margin-right:auto;display:block;}
canvas {width:100%;text-align:center;margin-left:auto;margin-right:auto;display:block;}
iframe {width:60%;padding:10px;text-align:center;margin-left:auto;margin-right:auto;display:block;}

</style>

</head>
<body>



<h1>Learn how to animate a rocket <br /> in Objective-C using SpriteKit</h1>

<div id="myDIV"><h2> Begin by setting up your scene.</h2></div>
<div id="myDIV"><
<pre>
-(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;
}
</pre>
</div>
<div id="myDIV"><h2> Now call the nosecone when touch begins.</h2></div>
<div id="myDIV"><pre>
-(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];
}
}
</pre></div>
<div id="myDIV1"><h2> Call the ship when dragging the touch across your screen. </h2></div>
<div id="myDIV">
<pre>
-(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];
}
}
</pre>
</div>
<div id="myDIV2"><h2> Finally, call the trunk on touch release. </h2></div>
<div id="myDIV">
<pre>
-(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];
}
}
</pre>
</div>
<div id="myDIV5"><h2> Now hit Run, and enjoy:</h2>
</div>

<iframe src="http://player.vimeo.com/video/107094184" width="500" height="861" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

<a href="https://github.com/jbdunne/Rocket-Animation-with-Obj-C"><h2>The full Obj C repo is available here.</h2></a>
</body>
</html>