Skip to content

Commit 009410e

Browse files
committed
Merge pull request #1120 from LearnCocos2D/develop
Swift fixes for v3.4 (actions: sequence, spawn / physics: joint, shape)
2 parents c68f1b1 + 4ad0415 commit 009410e

7 files changed

+123
-1
lines changed

cocos2d/CCActionInterval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
* @return New action sequence.
212212
*/
213213
+ (id)actionWithArray: (NSArray*) arrayOfActions;
214+
- (id)initWithArray:(NSArray*)arrayOfActions;
214215

215216
// purposefully undocumented: no point in having this documented if you can just create a list/array with 2 actions
216217
+ (id)actionOne:(CCActionFiniteTime*)actionOne two:(CCActionFiniteTime*)actionTwo;
@@ -326,6 +327,7 @@
326327
* @see CCActionSequence
327328
*/
328329
+ (id)actionWithArray:(NSArray*)arrayOfActions;
330+
- (id)actionWithArray:(NSArray*)arrayOfActions;
329331

330332
// purposefully undocumented: no point in having this documented if you can just create a list/array with 2 actions
331333
+ (id)actionOne:(CCActionFiniteTime*)one two:(CCActionFiniteTime*)two;

cocos2d/CCActionInterval.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ +(id) actionWithArray: (NSArray*) actions
155155

156156
return prev;
157157
}
158+
-(id) initWithArray:(NSArray *)actions
159+
{
160+
// this is backwards because it's "safer" as a quick Swift fix for v3.4
161+
return [CCActionSequence actionWithArray:actions];
162+
}
158163

159164
+(id) actionOne: (CCActionFiniteTime*) one two: (CCActionFiniteTime*) two
160165
{
@@ -418,6 +423,11 @@ +(id) actionWithArray: (NSArray*) actions
418423

419424
return prev;
420425
}
426+
-(id) initWithArray: (NSArray*) actions
427+
{
428+
// this is backwards because it's "safer" as a quick Swift fix for v3.4
429+
return [CCActionSpawn actionWithArray:actions];
430+
}
421431

422432
+(id) actionOne: (CCActionFiniteTime*) one two: (CCActionFiniteTime*) two
423433
{

cocos2d/CCPhysicsJoint.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
5454
+(CCPhysicsJoint *)connectedPivotJointWithBodyA:(CCPhysicsBody *)bodyA
5555
bodyB:(CCPhysicsBody *)bodyB
5656
anchorA:(CGPoint)anchorA;
57+
// needed for Swift
58+
-(CCPhysicsJoint *)initWithPivotJointWithBodyA:(CCPhysicsBody *)bodyA
59+
bodyB:(CCPhysicsBody *)bodyB
60+
anchorA:(CGPoint)anchorA;
5761

5862
/// -----------------------------------------------------------------------
5963
/// @name Creating Distance Joints
@@ -76,6 +80,11 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
7680
bodyB:(CCPhysicsBody *)bodyB
7781
anchorA:(CGPoint)anchorA
7882
anchorB:(CGPoint)anchorB;
83+
// needed for Swift
84+
-(CCPhysicsJoint *)initWithDistanceJointWithBodyA:(CCPhysicsBody *)bodyA
85+
bodyB:(CCPhysicsBody *)bodyB
86+
anchorA:(CGPoint)anchorA
87+
anchorB:(CGPoint)anchorB;
7988

8089
/**
8190
* Creates and returns a pivot joint between the two bodies and keeps the distance of the two anchor points within the range.
@@ -97,6 +106,13 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
97106
anchorB:(CGPoint)anchorB
98107
minDistance:(CGFloat)min
99108
maxDistance:(CGFloat)max;
109+
// needed for Swift
110+
-(CCPhysicsJoint *)initWithDistanceJointWithBodyA:(CCPhysicsBody *)bodyA
111+
bodyB:(CCPhysicsBody *)bodyB
112+
anchorA:(CGPoint)anchorA
113+
anchorB:(CGPoint)anchorB
114+
minDistance:(CGFloat)min
115+
maxDistance:(CGFloat)max;
100116

101117
/// -----------------------------------------------------------------------
102118
/// @name Creating Spring Joints
@@ -124,6 +140,14 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
124140
restLength:(CGFloat)restLength
125141
stiffness:(CGFloat)stiffness
126142
damping:(CGFloat)damping;
143+
// needed for Swift
144+
-(CCPhysicsJoint *)initWithSpringJointWithBodyA:(CCPhysicsBody *)bodyA
145+
bodyB:(CCPhysicsBody *)bodyB
146+
anchorA:(CGPoint)anchorA
147+
anchorB:(CGPoint)anchorB
148+
restLength:(CGFloat)restLength
149+
stiffness:(CGFloat)stiffness
150+
damping:(CGFloat)damping;
127151

128152
/**
129153
* Creates and returns a rotary spring joint between the two bodies.
@@ -143,6 +167,12 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
143167
restAngle:(CGFloat)restAngle
144168
stiffness:(CGFloat)stiffness
145169
damping:(CGFloat)damping;
170+
// needed for Swift
171+
-(CCPhysicsJoint *)initWithRotarySpringJointWithBodyA:(CCPhysicsBody *)bodyA
172+
bodyB:(CCPhysicsBody *)bodyB
173+
restAngle:(CGFloat)restAngle
174+
stiffness:(CGFloat)stiffness
175+
damping:(CGFloat)damping;
146176

147177

148178
// This method was misspelled. Please change "stifness" to "stiffness".
@@ -167,6 +197,10 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
167197
+(CCPhysicsJoint *)connectedMotorJointWithBodyA:(CCPhysicsBody *)bodyA
168198
bodyB:(CCPhysicsBody *)bodyB
169199
rate:(CGFloat)rate;
200+
// needed for Swift
201+
-(CCPhysicsJoint *)initWithMotorJointWithBodyA:(CCPhysicsBody *)bodyA
202+
bodyB:(CCPhysicsBody *)bodyB
203+
rate:(CGFloat)rate;
170204

171205

172206
/// -----------------------------------------------------------------------
@@ -189,6 +223,11 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
189223
bodyB:(CCPhysicsBody *)bodyB
190224
min:(CGFloat)min
191225
max:(CGFloat)max;
226+
// needed for Swift
227+
-(CCPhysicsJoint *)initWithRotaryLimitJointWithBodyA:(CCPhysicsBody *)bodyA
228+
bodyB:(CCPhysicsBody *)bodyB
229+
min:(CGFloat)min
230+
max:(CGFloat)max;
192231

193232

194233
/// -----------------------------------------------------------------------
@@ -212,6 +251,11 @@ A CCPhysicsJoint connects two CCPhysicsBody objects together, like a joint betwe
212251
bodyB:(CCPhysicsBody *)bodyB
213252
phase:(CGFloat)phase
214253
ratchet:(CGFloat)ratchet;
254+
// needed for Swift
255+
-(CCPhysicsJoint *)initWithRatchetJointWithBodyA:(CCPhysicsBody *)bodyA
256+
bodyB:(CCPhysicsBody *)bodyB
257+
phase:(CGFloat)phase
258+
ratchet:(CGFloat)ratchet;
215259

216260
/// -----------------------------------------------------------------------
217261
/// @name Removing a Physics Joint

cocos2d/CCPhysicsJoint.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ +(CCPhysicsJoint *)connectedPivotJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CC
9999

100100
return joint;
101101
}
102+
-(CCPhysicsJoint *)initWithPivotJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB anchorA:(CGPoint)anchorA
103+
{
104+
return [CCPhysicsJoint connectedPivotJointWithBodyA:bodyA bodyB:bodyB anchorA:anchorA];
105+
}
102106

103107
+(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
104108
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
@@ -111,6 +115,11 @@ +(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:
111115

112116
return joint;
113117
}
118+
-(CCPhysicsJoint *)initWithDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
119+
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
120+
{
121+
return [CCPhysicsJoint connectedDistanceJointWithBodyA:bodyA bodyB:bodyB anchorA:anchorA anchorB:anchorB];
122+
}
114123

115124
+(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
116125
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
@@ -124,6 +133,12 @@ +(CCPhysicsJoint *)connectedDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:
124133

125134
return joint;
126135
}
136+
-(CCPhysicsJoint *)initWithDistanceJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
137+
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
138+
minDistance:(CGFloat)min maxDistance:(CGFloat)max
139+
{
140+
return [CCPhysicsJoint connectedDistanceJointWithBodyA:bodyA bodyB:bodyB anchorA:anchorA anchorB:anchorB minDistance:min maxDistance:max];
141+
}
127142

128143
+(CCPhysicsJoint *)connectedSpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
129144
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
@@ -138,6 +153,12 @@ +(CCPhysicsJoint *)connectedSpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(C
138153

139154
return joint;
140155
}
156+
-(CCPhysicsJoint *)initWithSpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
157+
anchorA:(CGPoint)anchorA anchorB:(CGPoint)anchorB
158+
restLength:(CGFloat)restLength stiffness:(CGFloat)stiffness damping:(CGFloat)damping
159+
{
160+
return [CCPhysicsJoint connectedSpringJointWithBodyA:bodyA bodyB:bodyB anchorA:anchorA anchorB:anchorB restLength:restLength stiffness:stiffness damping:damping];
161+
}
141162

142163

143164

@@ -161,6 +182,13 @@ +(CCPhysicsJoint *)connectedRotarySpringJointWithBodyA:(CCPhysicsBody *)bodyA bo
161182
[joint addToPhysicsNode:bodyA.physicsNode];
162183
return joint;
163184
}
185+
-(CCPhysicsJoint *)initWithRotarySpringJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
186+
restAngle:(CGFloat)restAngle
187+
stiffness:(CGFloat)stiffness
188+
damping:(CGFloat)damping
189+
{
190+
return [CCPhysicsJoint connectedRotarySpringJointWithBodyA:bodyA bodyB:bodyB restAngle:restAngle stiffness:stiffness damping:damping];
191+
}
164192

165193

166194
+(CCPhysicsJoint *)connectedMotorJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
@@ -173,6 +201,10 @@ +(CCPhysicsJoint *)connectedMotorJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CC
173201
[joint addToPhysicsNode:bodyA.physicsNode];
174202
return joint;
175203
}
204+
-(CCPhysicsJoint *)initWithMotorJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB rate:(CGFloat)rate
205+
{
206+
return [CCPhysicsJoint connectedMotorJointWithBodyA:bodyA bodyB:bodyB rate:rate];
207+
}
176208

177209

178210

@@ -187,6 +219,10 @@ +(CCPhysicsJoint *)connectedRotaryLimitJointWithBodyA:(CCPhysicsBody *)bodyA bod
187219
[joint addToPhysicsNode:bodyA.physicsNode];
188220
return joint;
189221
}
222+
-(CCPhysicsJoint *)initWithRotaryLimitJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB min:(cpFloat)min max:(cpFloat)max
223+
{
224+
return [CCPhysicsJoint connectedRotaryLimitJointWithBodyA:bodyA bodyB:bodyB min:min max:max];
225+
}
190226

191227

192228
+(CCPhysicsJoint *)connectedRatchetJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
@@ -200,6 +236,12 @@ +(CCPhysicsJoint *)connectedRatchetJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(
200236
[joint addToPhysicsNode:bodyA.physicsNode];
201237
return joint;
202238
}
239+
-(CCPhysicsJoint *)initWithRatchetJointWithBodyA:(CCPhysicsBody *)bodyA bodyB:(CCPhysicsBody *)bodyB
240+
phase:(cpFloat)phase
241+
ratchet:(cpFloat)ratchet
242+
{
243+
return [CCPhysicsJoint connectedRatchetJointWithBodyA:bodyA bodyB:bodyB phase:phase ratchet:ratchet];
244+
}
203245

204246

205247

cocos2d/CCPhysicsShape.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Using simple shapes instead of composite ones can make collision handling code s
5050
* @return The CCPhysicsShape Object.
5151
*/
5252
+(CCPhysicsShape *)circleShapeWithRadius:(CGFloat)radius center:(CGPoint)center;
53+
// needed for Swift
54+
-(CCPhysicsShape *)initWithCircleShapeWithRadius:(CGFloat)radius center:(CGPoint)center;
5355

5456
/**
5557
* Creates and returns a physics box shape with rounded corners.
@@ -60,6 +62,8 @@ Using simple shapes instead of composite ones can make collision handling code s
6062
* @return The CCPhysicsShape Object.
6163
*/
6264
+(CCPhysicsShape *)rectShape:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;
65+
// needed for Swift
66+
-(CCPhysicsShape *)initWithRectShape:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;
6367

6468
/**
6569
* Creates and returns a pill shaped physics shape with rounded corners that stretches from 'start' to 'end'.
@@ -71,6 +75,8 @@ Using simple shapes instead of composite ones can make collision handling code s
7175
* @return The CCPhysicsShape Object.
7276
*/
7377
+(CCPhysicsShape *)pillShapeFrom:(CGPoint)from to:(CGPoint)to cornerRadius:(CGFloat)cornerRadius;
78+
// needed for Swift
79+
-(CCPhysicsShape *)initWithPillShapeFrom:(CGPoint)from to:(CGPoint)to cornerRadius:(CGFloat)cornerRadius;
7480

7581
/**
7682
* Creates and returns a convex polygon physics shape with rounded corners.
@@ -89,6 +95,8 @@ Using simple shapes instead of composite ones can make collision handling code s
8995
* @see [Definition: Convex vs Concave](http://en.wikipedia.org/wiki/Convex_and_concave_polygons)
9096
*/
9197
+(CCPhysicsShape *)polygonShapeWithPoints:(CGPoint *)points count:(NSUInteger)count cornerRadius:(CGFloat)cornerRadius;
98+
// needed for Swift
99+
-(CCPhysicsShape *)initWithPolygonShapeWithPoints:(CGPoint *)points count:(NSUInteger)count cornerRadius:(CGFloat)cornerRadius;
92100

93101

94102
/// -----------------------------------------------------------------------

cocos2d/CCPhysicsShape.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,37 @@ +(CCPhysicsShape *)circleShapeWithRadius:(CGFloat)radius center:(CGPoint)center
6565
{
6666
return [[CCPhysicsCircleShape alloc] initWithRadius:radius center:center];
6767
}
68+
-(CCPhysicsShape *)initWithCircleShapeWithRadius:(CGFloat)radius center:(CGPoint)center
69+
{
70+
return [[CCPhysicsCircleShape alloc] initWithRadius:radius center:center];
71+
}
6872

6973
+(CCPhysicsShape *)rectShape:(CGRect)rect cornerRadius:(CGFloat)cornerRadius
7074
{
7175
return [[CCPhysicsPolyShape alloc] initWithRect:rect cornerRadius:cornerRadius];
7276
}
77+
-(CCPhysicsShape *)initWithRectShape:(CGRect)rect cornerRadius:(CGFloat)cornerRadius
78+
{
79+
return [[CCPhysicsPolyShape alloc] initWithRect:rect cornerRadius:cornerRadius];
80+
}
7381

7482
+(CCPhysicsShape *)pillShapeFrom:(CGPoint)from to:(CGPoint)to cornerRadius:(CGFloat)cornerRadius
7583
{
7684
return [[CCPhysicsSegmentShape alloc] initFrom:from to:to cornerRadius:cornerRadius];
7785
}
86+
-(CCPhysicsShape *)initWithPillShapeFrom:(CGPoint)from to:(CGPoint)to cornerRadius:(CGFloat)cornerRadius
87+
{
88+
return [[CCPhysicsSegmentShape alloc] initFrom:from to:to cornerRadius:cornerRadius];
89+
}
7890

7991
+(CCPhysicsShape *)polygonShapeWithPoints:(CGPoint *)points count:(NSUInteger)count cornerRadius:(CGFloat)cornerRadius
8092
{
8193
return [[CCPhysicsPolyShape alloc] initWithPolygonFromPoints:points count:count cornerRadius:cornerRadius];
8294
}
95+
-(CCPhysicsShape *)initWithPolygonShapeWithPoints:(CGPoint *)points count:(NSUInteger)count cornerRadius:(CGFloat)cornerRadius
96+
{
97+
return [[CCPhysicsPolyShape alloc] initWithPolygonFromPoints:points count:count cornerRadius:cornerRadius];
98+
}
8399

84100
-(cpTransform)shapeTransform
85101
{

cocos2d/cocos2d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
#import "OALSimpleAudio.h"
131131

132132
// Retiring
133-
//#import "CCAnimation.h"
133+
#import "CCAnimation.h" // put this back for v3.4 because it's still in use, and would otherwise be unavailable to Swift
134134
//#import "CCAnimationCache.h"
135135
//#import "CCActionManager.h"
136136
//#import "ccFPSImages.h"

0 commit comments

Comments
 (0)