Skip to content

Commit f2fc9cb

Browse files
committed
Updated iOS templates
Former-commit-id: 994bcc2
1 parent 4deca65 commit f2fc9cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+665
-195
lines changed

AUTHORS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ People and companies, who have contributed, in alphabetical order.
2424
* Apportable (http://www.apportable.com)
2525
Making it all happen
2626

27+
* Christian Enevoldsen
28+
Improved scroll view class
29+
2730
* Dominik Hadl
2831
Templates, scripts and other ninja stuff
2932

@@ -50,9 +53,6 @@ People and companies, who have contributed, in alphabetical order.
5053
Coordination and planning
5154
Sprite Builder integration
5255
Countless other contributions
53-
54-
* Christian Enevoldsen
55-
Improved scroll view class
5656

5757
Thanks to Wangsheng, Shintaro Kaneko, frranck and Yannick Loriot, Magician, masanorythm, Jogn Vu for various minor contributions.
5858
Also thanks to all those who contributed on git, helped us testing, and took part in the discussions even if their suggestions didn't make it to release.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// AppDelegate.h
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
#import "cocos2d.h"
11+
12+
@interface AppDelegate : CCAppDelegate
13+
@end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// AppDelegate.m
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
#import "AppDelegate.h"
11+
#import "IntroScene.h"
12+
#import "HelloWorldScene.h"
13+
14+
@implementation AppDelegate
15+
16+
//
17+
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18+
{
19+
// This is the only app delegate method you need to implement when inheriting from CCAppDelegate.
20+
// This method is a good place to add one time setup code that only runs when your app is first launched.
21+
22+
// Setup Cocos2D with reasonable defaults for everything.
23+
// There are a number of simple options you can change.
24+
// If you want more flexibility, you can configure Cocos2D yourself instead of calling setupCocos2dWithOptions:.
25+
[self setupCocos2dWithOptions:@{
26+
// Show the FPS and draw call label.
27+
CCSetupShowDebugStats: @(YES),
28+
29+
// More examples of options you might want to fiddle with:
30+
// (See CCAppDelegate.h for more information)
31+
32+
// Use a 16 bit color buffer:
33+
// CCSetupPixelFormat: kEAGLColorFormatRGB565,
34+
// Use a simplified coordinate system that is shared across devices.
35+
// CCSetupScreenMode: CCScreenModeFixed,
36+
// Run in portrait mode.
37+
// CCSetupScreenOrientation: CCScreenOrientationPortrait,
38+
// Run at a reduced framerate.
39+
// CCSetupAnimationInterval: @(1.0/30.0),
40+
// Run the fixed timestep extra fast.
41+
// CCSetupFixedUpdateInterval: @(1.0/180.0),
42+
// Make iPad's act like they run at a 2x content scale. (iPad retina 4x)
43+
// CCSetupTabletScale2X: @(YES),
44+
}];
45+
46+
return YES;
47+
}
48+
49+
-(CCScene *)startScene
50+
{
51+
// This method should return the very first scene to be run when your app starts.
52+
return [IntroScene scene];
53+
}
54+
55+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// HelloWorldScene.h
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
// Importing cocos2d.h and cocos2d-ui.h, will import anything you need to start using Cocos2D v3
11+
#import "cocos2d.h"
12+
#import "cocos2d-ui.h"
13+
14+
// -----------------------------------------------------------------------
15+
16+
/**
17+
* The main scene
18+
*/
19+
@interface HelloWorldScene : CCScene
20+
21+
// -----------------------------------------------------------------------
22+
23+
+ (HelloWorldScene *)scene;
24+
- (id)init;
25+
26+
// -----------------------------------------------------------------------
27+
@end
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//
2+
// HelloWorldScene.m
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
#import "HelloWorldScene.h"
11+
#import "IntroScene.h"
12+
#import "NewtonScene.h"
13+
14+
// -----------------------------------------------------------------------
15+
#pragma mark - HelloWorldScene
16+
// -----------------------------------------------------------------------
17+
18+
@implementation HelloWorldScene
19+
{
20+
CCSprite *_sprite;
21+
}
22+
23+
// -----------------------------------------------------------------------
24+
#pragma mark - Create & Destroy
25+
// -----------------------------------------------------------------------
26+
27+
+ (HelloWorldScene *)scene
28+
{
29+
return [[self alloc] init];
30+
}
31+
32+
// -----------------------------------------------------------------------
33+
34+
- (id)init
35+
{
36+
// Apple recommend assigning self with supers return value
37+
self = [super init];
38+
if (!self) return(nil);
39+
40+
// Enable touch handling on scene node
41+
self.userInteractionEnabled = YES;
42+
43+
// Create a colored background (Dark Grey)
44+
CCNodeColor *background = [CCNodeColor nodeWithColor:[CCColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f]];
45+
[self addChild:background];
46+
47+
// Add a sprite
48+
_sprite = [CCSprite spriteWithImageNamed:@"Icon-72.png"];
49+
_sprite.position = ccp(self.contentSize.width/2,self.contentSize.height/2);
50+
[self addChild:_sprite];
51+
52+
// Animate sprite with action
53+
CCActionRotateBy* actionSpin = [CCActionRotateBy actionWithDuration:1.5f angle:360];
54+
[_sprite runAction:[CCActionRepeatForever actionWithAction:actionSpin]];
55+
56+
// Create a back button
57+
CCButton *backButton = [CCButton buttonWithTitle:@"[ Menu ]" fontName:@"Verdana-Bold" fontSize:18.0f];
58+
backButton.positionType = CCPositionTypeNormalized;
59+
backButton.position = ccp(0.85f, 0.95f); // Top Right of screen
60+
[backButton setTarget:self selector:@selector(onBackClicked:)];
61+
[self addChild:backButton];
62+
63+
// done
64+
return self;
65+
}
66+
67+
// -----------------------------------------------------------------------
68+
69+
- (void)dealloc
70+
{
71+
// clean up code goes here
72+
}
73+
74+
// -----------------------------------------------------------------------
75+
#pragma mark - Enter & Exit
76+
// -----------------------------------------------------------------------
77+
78+
- (void)onEnter
79+
{
80+
// always call super onEnter first
81+
[super onEnter];
82+
83+
// In pre-v3, touch enable and scheduleUpdate was called here
84+
// In v3, touch is enabled by setting userInterActionEnabled for the individual nodes
85+
// Per frame update is automatically enabled, if update is overridden
86+
87+
}
88+
89+
// -----------------------------------------------------------------------
90+
91+
- (void)onExit
92+
{
93+
// always call super onExit last
94+
[super onExit];
95+
}
96+
97+
// -----------------------------------------------------------------------
98+
#pragma mark - Touch Handler
99+
// -----------------------------------------------------------------------
100+
101+
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
102+
CGPoint touchLoc = [touch locationInNode:self];
103+
104+
// Log touch location
105+
CCLOG(@"Move sprite to @ %@",NSStringFromCGPoint(touchLoc));
106+
107+
// Move our sprite to touch location
108+
CCActionMoveTo *actionMove = [CCActionMoveTo actionWithDuration:1.0f position:touchLoc];
109+
[_sprite runAction:actionMove];
110+
}
111+
112+
// -----------------------------------------------------------------------
113+
#pragma mark - Button Callbacks
114+
// -----------------------------------------------------------------------
115+
116+
- (void)onBackClicked:(id)sender
117+
{
118+
// back to intro scene with transition
119+
[[CCDirector sharedDirector] replaceScene:[IntroScene scene]
120+
withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionRight duration:1.0f]];
121+
}
122+
123+
- (void)onNewtonClicked:(id)sender
124+
{
125+
[[CCDirector sharedDirector] pushScene:[NewtonScene scene] withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionLeft duration:1.0f]];
126+
}
127+
128+
// -----------------------------------------------------------------------
129+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// IntroScene.h
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
// Importing cocos2d.h and cocos2d-ui.h, will import anything you need to start using cocos2d-v3
11+
#import "cocos2d.h"
12+
#import "cocos2d-ui.h"
13+
14+
// -----------------------------------------------------------------------
15+
16+
/**
17+
* The intro scene
18+
* Note, that scenes should now be based on CCScene, and not CCLayer, as previous versions
19+
* Main usage for CCLayer now, is to make colored backgrounds (rectangles)
20+
*
21+
*/
22+
@interface IntroScene : CCScene
23+
24+
// -----------------------------------------------------------------------
25+
26+
+ (IntroScene *)scene;
27+
- (id)init;
28+
29+
// -----------------------------------------------------------------------
30+
@end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// IntroScene.m
3+
// ___PROJECTNAME___
4+
//
5+
// Created by ___FULLUSERNAME___ on ___DATE___.
6+
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
7+
//
8+
// -----------------------------------------------------------------------
9+
10+
// Import the interfaces
11+
#import "IntroScene.h"
12+
#import "HelloWorldScene.h"
13+
#import "NewtonScene.h"
14+
15+
// -----------------------------------------------------------------------
16+
#pragma mark - IntroScene
17+
// -----------------------------------------------------------------------
18+
19+
@implementation IntroScene
20+
21+
// -----------------------------------------------------------------------
22+
#pragma mark - Create & Destroy
23+
// -----------------------------------------------------------------------
24+
25+
+ (IntroScene *)scene
26+
{
27+
return [[self alloc] init];
28+
}
29+
30+
// -----------------------------------------------------------------------
31+
32+
- (id)init
33+
{
34+
// Apple recommend assigning self with supers return value
35+
self = [super init];
36+
if (!self) return(nil);
37+
38+
// Create a colored background (Dark Grey)
39+
CCNodeColor *background = [CCNodeColor nodeWithColor:[CCColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f]];
40+
[self addChild:background];
41+
42+
// Hello world
43+
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Chalkduster" fontSize:36.0f];
44+
label.positionType = CCPositionTypeNormalized;
45+
label.color = [CCColor redColor];
46+
label.position = ccp(0.5f, 0.5f); // Middle of screen
47+
[self addChild:label];
48+
49+
// Spinning scene button
50+
CCButton *spinningButton = [CCButton buttonWithTitle:@"[ Simple Sprite ]" fontName:@"Verdana-Bold" fontSize:18.0f];
51+
spinningButton.positionType = CCPositionTypeNormalized;
52+
spinningButton.position = ccp(0.5f, 0.35f);
53+
[spinningButton setTarget:self selector:@selector(onSpinningClicked:)];
54+
[self addChild:spinningButton];
55+
56+
// Next scene button
57+
CCButton *newtonButton = [CCButton buttonWithTitle:@"[ Newton Physics ]" fontName:@"Verdana-Bold" fontSize:18.0f];
58+
newtonButton.positionType = CCPositionTypeNormalized;
59+
newtonButton.position = ccp(0.5f, 0.20f);
60+
[newtonButton setTarget:self selector:@selector(onNewtonClicked:)];
61+
[self addChild:newtonButton];
62+
63+
// done
64+
return self;
65+
}
66+
67+
// -----------------------------------------------------------------------
68+
#pragma mark - Button Callbacks
69+
// -----------------------------------------------------------------------
70+
71+
- (void)onSpinningClicked:(id)sender
72+
{
73+
// start spinning scene with transition
74+
[[CCDirector sharedDirector] replaceScene:[HelloWorldScene scene]
75+
withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionLeft duration:1.0f]];
76+
}
77+
78+
- (void)onNewtonClicked:(id)sender
79+
{
80+
// start newton scene with transition
81+
// the current scene is pushed, and thus needs popping to be brought back. This is done in the newton scene, when pressing back (upper left corner)
82+
[[CCDirector sharedDirector] pushScene:[NewtonScene scene]
83+
withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionLeft duration:1.0f]];
84+
}
85+
86+
// -----------------------------------------------------------------------
87+
@end

0 commit comments

Comments
 (0)