Changes

Jump to: navigation, search

An iOS 7 Sprite Kit Game Tutorial

1,653 bytes removed, 21:40, 12 December 2013
Creating the Arrow Sprite Node
The code creates a new SKSpriteNode object, positions it to the right of the archer sprite node and assigns it the name arrowNode. A physics body is then assigned to the node, using the size of the node itself as the boundary of the body and enabling precision collision detection. Finally the node is returned.
== Creating the Arrow Sprite Node ==
At this point in the tutorial, the archer sprite node goes through an animation sequence of loading and firing an arrow but no actual arrow is being launched across the scene. In order to implement this, a new sprite node needs to be added to the ArcheryScene. This node will be textured with an image of an arrow and will be placed to the right of the archer sprite at the end of the animation sequence. A physics body will be associated with the arrow and an impulse force applied to it to propel it across the scene as though shot by the archer’s bow.
 
Begin by locating the ArrowTexture.png file in the SpriteImages folder of the sample code archive and drag and drop it onto the Supporting Files folder in the Xcode project navigator panel. Next, add a new method named createArrowNode within the ArcheryScene.m file so that it reads as follows:
 
<pre>
- (SKSpriteNode *) createArrowNode
{
SKSpriteNode *arrow =
[[SKSpriteNode alloc] initWithImageNamed:@"ArrowTexture.png"];
 
arrow.position = CGPointMake(CGRectGetMinX(self.frame)+100,
CGRectGetMidY(self.frame));
 
arrow.name = @"arrowNode";
 
arrow.physicsBody =
[SKPhysicsBody bodyWithRectangleOfSize:arrow.frame.size];
 
arrow.physicsBody.usesPreciseCollisionDetection = YES;
 
return arrow;
}
</pre>
 
The code creates a new SKSpriteNode object, positions it to the right of the archer sprite node and assigns it the name arrowNode. A physics body is then assigned to the node, using the size of the node itself as the boundary of the body and enabling precision collision detection. Finally the node is returned.
== Shooting the Arrow ==

Navigation menu