Skip to content

Commit

Permalink
Added load skeleton pose test case
Browse files Browse the repository at this point in the history
  • Loading branch information
vladubogdan committed Jun 17, 2013
1 parent c1497e1 commit cb91adf
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 2 deletions.
6 changes: 6 additions & 0 deletions GameDevHelperAPI-SpriteKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
6EE13B31176F3CE50047FEB2 /* LoadSkeletonScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EE13B30176F3CE50047FEB2 /* LoadSkeletonScene.m */; };
6EE13B35176F3EC90047FEB2 /* skeletons in Resources */ = {isa = PBXBuildFile; fileRef = 6EE13B33176F3EC90047FEB2 /* skeletons */; };
6EE13B39176F52F50047FEB2 /* Officer.atlasc in Resources */ = {isa = PBXBuildFile; fileRef = 6EE13B38176F52F50047FEB2 /* Officer.atlasc */; };
6EE13B3C176F596A0047FEB2 /* LoadSkeletonPosesScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EE13B3B176F596A0047FEB2 /* LoadSkeletonPosesScene.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -99,6 +100,8 @@
6EE13B30176F3CE50047FEB2 /* LoadSkeletonScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadSkeletonScene.m; sourceTree = "<group>"; };
6EE13B33176F3EC90047FEB2 /* skeletons */ = {isa = PBXFileReference; lastKnownFileType = folder; path = skeletons; sourceTree = "<group>"; };
6EE13B38176F52F50047FEB2 /* Officer.atlasc */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Officer.atlasc; sourceTree = "<group>"; };
6EE13B3A176F596A0047FEB2 /* LoadSkeletonPosesScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadSkeletonPosesScene.h; sourceTree = "<group>"; };
6EE13B3B176F596A0047FEB2 /* LoadSkeletonPosesScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadSkeletonPosesScene.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -185,6 +188,8 @@
6EE13B13176F04310047FEB2 /* LoadPhysicalSpritesScene.m */,
6EE13B2F176F3CE50047FEB2 /* LoadSkeletonScene.h */,
6EE13B30176F3CE50047FEB2 /* LoadSkeletonScene.m */,
6EE13B3A176F596A0047FEB2 /* LoadSkeletonPosesScene.h */,
6EE13B3B176F596A0047FEB2 /* LoadSkeletonPosesScene.m */,
6ECC0CEE176B331100763EF7 /* Spaceship.png */,
6ECC0CF0176B331100763EF7 /* Images.xcassets */,
6ECC0CD7176B331100763EF7 /* Supporting Files */,
Expand Down Expand Up @@ -357,6 +362,7 @@
6EE13B2C176F34C60047FEB2 /* GHSkeletalAnimationCache.mm in Sources */,
6EE13B2D176F34C60047FEB2 /* GHSkeleton.mm in Sources */,
6EE13B29176F34C60047FEB2 /* GHBone.mm in Sources */,
6EE13B3C176F596A0047FEB2 /* LoadSkeletonPosesScene.m in Sources */,
6EE13B2A176F34C60047FEB2 /* GHBoneSkin.mm in Sources */,
6ECC0CE1176B331100763EF7 /* AppDelegate.m in Sources */,
6ECC0CDD176B331100763EF7 /* main.m in Sources */,
Expand Down
Binary file not shown.
18 changes: 18 additions & 0 deletions GameDevHelperAPI-SpriteKit/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<action selector="loadSkeleton:" destination="LVB-YS-i5n" eventType="touchUpInside" id="b7F-ET-swE"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="f8u-gN-xjA">
<rect key="frame" x="89" y="142" width="143" height="23"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Load Skeleton Poses">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="loadSkeletonPose:" destination="LVB-YS-i5n" eventType="touchUpInside" id="x3J-Lo-FXT"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zWH-un-G4y">
<rect key="frame" x="20" y="20" width="45" height="23"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand All @@ -80,6 +95,7 @@
<outlet property="backButton" destination="zWH-un-G4y" id="bwS-oN-zsf"/>
<outlet property="loadPhysicalSpritesBut" destination="zNm-9H-0fS" id="60h-qn-R9Y"/>
<outlet property="loadSkeletonBut" destination="kMh-1Y-bqg" id="aUM-Hq-nIA"/>
<outlet property="loadSkeletonPoseBut" destination="f8u-gN-xjA" id="9Bl-Hl-Ai4"/>
<outlet property="loadSpritesBut" destination="7pN-Vn-mMz" id="5NX-ea-0CW"/>
</connections>
</viewController>
Expand All @@ -97,10 +113,12 @@
<relationship kind="action" name="backToMenu:"/>
<relationship kind="action" name="loadPhysicalSprites:"/>
<relationship kind="action" name="loadSkeleton:"/>
<relationship kind="action" name="loadSkeletonPose:"/>
<relationship kind="action" name="loadSpritesUsingSpriteKit:"/>
<relationship kind="outlet" name="backButton" candidateClass="UIButton"/>
<relationship kind="outlet" name="loadPhysicalSpritesBut" candidateClass="UIButton"/>
<relationship kind="outlet" name="loadSkeletonBut" candidateClass="UIButton"/>
<relationship kind="outlet" name="loadSkeletonPoseBut" candidateClass="UIButton"/>
<relationship kind="outlet" name="loadSpritesBut" candidateClass="UIButton"/>
</relationships>
</class>
Expand Down
18 changes: 18 additions & 0 deletions GameDevHelperAPI-SpriteKit/LoadSkeletonPosesScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LoadSkeletonPosesScene.h
// GameDevHelperAPI-SpriteKit
//

// Copyright (c) 2013 Bogdan Vladu. All rights reserved.
//

#import <SpriteKit/SpriteKit.h>

#import "GameDevHelper.h"

@interface LoadSkeletonPosesScene : SKScene
{
GHSkeleton* skeleton;
int currentPose;
}
@end
97 changes: 97 additions & 0 deletions GameDevHelperAPI-SpriteKit/LoadSkeletonPosesScene.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// LoadSkeletonPosesScene.m
// GameDevHelperAPI-SpriteKit
//
// Created by Bogdan Vladu on 6/14/13.
// Copyright (c) 2013 Bogdan Vladu. All rights reserved.
//

#import "LoadSkeletonPosesScene.h"

@implementation LoadSkeletonPosesScene

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

self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];


[self buildWorld];

SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
myLabel.text = @"Load skeleton poses using Sprite Kit";
myLabel.fontSize = 12;
myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));

SKLabelNode *myLabel2 = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
myLabel2.text = @"from SpriteHelper 2 generated files.";
myLabel2.fontSize = 12;
myLabel2.position = CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame)-12);


[self addChild:myLabel];
[self addChild:myLabel2];
}
return self;
}

- (void)buildWorld {

// Configure physics for the world.
self.physicsWorld.gravity = CGPointMake(0, -2); // no gravity

self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];

if(skeleton == nil){
skeleton = [GHSkeleton skeletonWithFile:@"Officer_Officer"
directory:@"skeletons"];

skeleton.position = location;

[self addChild:skeleton];
}
else{
[self changePose];
}
}
}

-(void)changePose{

NSArray *poseNames = [NSArray arrayWithObjects:
@"DefaultPose",
@"BowPose",
@"DeathPose",
@"HatWave",
@"IdlePose",
@"PushPose",
@"ShootPose",
nil];

NSString* finalPoseName = [poseNames objectAtIndex:currentPose];
++currentPose;

if(currentPose >= [poseNames count])
currentPose = 0;

[skeleton setPoseWithName:finalPoseName];
}


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

@end
17 changes: 15 additions & 2 deletions GameDevHelperAPI-SpriteKit/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "LoadSimpleSpritesScene.h"
#import "LoadPhysicalSpritesScene.h"
#import "LoadSkeletonScene.h"
#import "LoadSkeletonPosesScene.h"

@interface ViewController ()
{
Expand All @@ -19,6 +20,7 @@ @interface ViewController ()
@property (nonatomic) IBOutlet UIButton *loadSpritesBut;
@property (nonatomic) IBOutlet UIButton *loadPhysicalSpritesBut;
@property (nonatomic) IBOutlet UIButton *loadSkeletonBut;
@property (nonatomic) IBOutlet UIButton *loadSkeletonPoseBut;
@end


Expand All @@ -39,7 +41,7 @@ -(void)goToScene{

- (void)viewDidLoad
{
menuButtons = @[_loadSpritesBut, _loadPhysicalSpritesBut, _loadSkeletonBut];
menuButtons = @[_loadSpritesBut, _loadPhysicalSpritesBut, _loadSkeletonBut, _loadSkeletonPoseBut];

[super viewDidLoad];

Expand Down Expand Up @@ -94,7 +96,18 @@ -(IBAction)loadSkeleton:(id)sender
[skView presentScene:scene];
}


-(IBAction)loadSkeletonPose:(id)sender
{
SKView * skView = (SKView *)self.view;

// Create and configure the scene.
SKScene * scene = [LoadSkeletonPosesScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

[self goToScene];
// Present the scene.
[skView presentScene:scene];
}



Expand Down

0 comments on commit cb91adf

Please sign in to comment.