Skip to content

Commit 80f7878

Browse files
committed
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-iphone into develop
2 parents 11cf00d + 3b16838 commit 80f7878

File tree

17 files changed

+720
-993
lines changed

17 files changed

+720
-993
lines changed

cocos2d-ui-tests/tests/CCRendererTest.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ -(void)setupInfiniteWindowTest
175175
CCNode *contentNode = self.contentNode;
176176
CGSize size = [CCDirector sharedDirector].designSize;
177177

178-
[self scheduleBlock:^(CCTimer *timer) {
178+
CCNode *node = [CCNode node];
179+
[self.contentNode addChild:node];
180+
181+
[node scheduleBlock:^(CCTimer *timer) {
179182
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
180183

181184
[rt begin];
@@ -383,7 +386,7 @@ - (void)setupProgressNodeTest
383386

384387
// Radial timer
385388
{
386-
NSString *image = @"Tiles/05.png";
389+
NSString *image = @"Tiles/06.png";
387390
CGPoint position = ccp(0.1, 0.25);
388391
CCTime interval = 1.0/60.0;
389392

@@ -407,7 +410,7 @@ - (void)setupProgressNodeTest
407410

408411
// Radial timer with animating midpoint.
409412
{
410-
NSString *image = @"Tiles/05.png";
413+
NSString *image = @"Tiles/06.png";
411414
CGPoint position = ccp(0.1, 0.5);
412415
CCTime interval = 1.0/60.0;
413416

@@ -432,7 +435,7 @@ - (void)setupProgressNodeTest
432435
}
433436

434437
{
435-
NSString *image = @"Tiles/05.png";
438+
NSString *image = @"Tiles/06.png";
436439
CGPoint position = ccp(0.2, 0.25);
437440
CCTime interval = 1.0/60.0;
438441

@@ -458,7 +461,7 @@ - (void)setupProgressNodeTest
458461
}
459462

460463
{
461-
NSString *image = @"Tiles/05.png";
464+
NSString *image = @"Tiles/06.png";
462465
CGPoint position = ccp(0.2, 0.5);
463466
CCTime interval = 1.0/60.0;
464467

@@ -484,7 +487,7 @@ - (void)setupProgressNodeTest
484487
}
485488

486489
{
487-
NSString *image = @"Tiles/05.png";
490+
NSString *image = @"Tiles/06.png";
488491
CGPoint position = ccp(0.3, 0.25);
489492
CCTime interval = 1.0/60.0;
490493

@@ -510,7 +513,7 @@ - (void)setupProgressNodeTest
510513
}
511514

512515
{
513-
NSString *image = @"Tiles/05.png";
516+
NSString *image = @"Tiles/06.png";
514517
CGPoint position = ccp(0.3, 0.5);
515518
CCTime interval = 1.0/60.0;
516519

@@ -536,7 +539,7 @@ - (void)setupProgressNodeTest
536539
}
537540

538541
{
539-
NSString *image = @"Tiles/05.png";
542+
NSString *image = @"Tiles/06.png";
540543
CGPoint position = ccp(0.4, 0.25);
541544
CCTime interval = 1.0/60.0;
542545

@@ -562,7 +565,7 @@ - (void)setupProgressNodeTest
562565
}
563566

564567
{
565-
NSString *image = @"Tiles/05.png";
568+
NSString *image = @"Tiles/06.png";
566569
CGPoint position = ccp(0.4, 0.5);
567570
CCTime interval = 1.0/60.0;
568571

@@ -588,7 +591,7 @@ - (void)setupProgressNodeTest
588591
}
589592

590593
{
591-
NSString *image = @"Tiles/05.png";
594+
NSString *image = @"Tiles/06.png";
592595
CGPoint position = ccp(0.5, 3.0/8.0);
593596

594597
CCSprite *sprite = [CCSprite spriteWithImageNamed:image];

cocos2d-ui/CCBReader/CCAnimationManager.h

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@
3030

3131
#pragma mark Animation Manager Delegate
3232

33+
/**
34+
* The animation manager delegate receives callbacks when animation sequences finishes playing.
35+
*/
3336
@protocol CCBAnimationManagerDelegate <NSObject>
3437

38+
/**
39+
* Called when an animation sequence has finished playing.
40+
* @param name The name of the sequence that just finished playing.
41+
*/
3542
- (void) completedAnimationSequenceNamed:(NSString*)name;
3643

3744
@end
3845

3946
#pragma mark Animation Manager
4047

48+
/**
49+
* The animation manager plays back animations, usually created by a tool such as SpriteBuilder. Any animation can have an arbitrary number of sequences (timelines) which each have keyframes for different properties.
50+
*/
4151
@interface CCAnimationManager : NSObject <CCSchedulerTarget>
4252
{
4353
NSMutableDictionary* _nodeSequences;
@@ -56,39 +66,56 @@
5666

5767
}
5868

59-
// Animation manager updates on a fixed timestep.
69+
/// If set to true the animation manager will run on a fixed time step, this is required to run animations toghether with physics.
6070
@property (nonatomic,assign) bool fixedTimestep;
6171

6272

63-
// Delegate.
73+
/// The animation manager delegate receives updates about the animations currently being played.
6474
@property (nonatomic,weak) NSObject<CCBAnimationManagerDelegate>* delegate;
6575

66-
// Currently running sequence name.
76+
/// The name of the currently running sequence (timeline).
6777
@property (unsafe_unretained, nonatomic,readonly) NSString* runningSequenceName;
6878

69-
// Last sequence name completed.
79+
/// The name of the last completed sequence (timeline).
7080
@property (nonatomic,readonly) NSString* lastCompletedSequenceName;
7181

72-
// Speed.
82+
/// Playback speed, default is 1 and corresponds to the normal playback speed. Use this property for fast forward or slow motion playback.
7383
@property (nonatomic,assign) float playbackSpeed;
7484

75-
// Pause.
85+
/// Set to true to pause the animation currently being run.
7686
@property (nonatomic,assign) bool paused;
7787

7888

7989

80-
// Run an animation.
90+
/**
91+
* Plays an animation sequence (timeline) by its name.
92+
* @param name The name of the sequence to play.
93+
*/
8194
- (void) runAnimationsForSequenceNamed:(NSString*)name;
95+
96+
/**
97+
* Plays an animation sequence (timeline) by its name, tweens smoothly to the new sequence.
98+
* @param name The name of the sequence to play.
99+
* @param tweenDuration Time to tween to the new sequence.
100+
*/
82101
- (void) runAnimationsForSequenceNamed:(NSString*)name tweenDuration:(float)tweenDuration;
83102

84-
// Animation call back.
103+
/**
104+
* Sets a block to be called when an animation sequence has finished playing.
105+
* @param b The block to call.
106+
*/
85107
-(void) setCompletedAnimationCallbackBlock:(void(^)(id sender))b;
86108

87109
#pragma mark Time Controls
88110

89111
//Renamed to jumpToSequenceNamed:time
90-
- (void)timeSeekForSequenceNamed:(NSString*)name time:(float)time __attribute__((deprecated));
112+
//- (void)timeSeekForSequenceNamed:(NSString*)name time:(float)time __attribute__((deprecated));
91113

114+
/**
115+
* Jumps to a specific time in a specific sequence (timeline).
116+
* @param name The name of the sequence to jump to.
117+
* @param time The time in the sequence.
118+
*/
92119
- (void)jumpToSequenceNamed:(NSString*)name time:(float)time;
93120

94121
@end

cocos2d-ui/CCButton.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ - (void) stateChanged
343343
- (void) setHitAreaExpansion:(float)hitAreaExpansion
344344
{
345345
_originalHitAreaExpansion = hitAreaExpansion;
346-
[super hitAreaExpansion];
346+
[super setHitAreaExpansion:hitAreaExpansion];
347347
}
348348

349349
- (float) hitAreaExpansion

cocos2d/CCNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ A common user pattern in building a Cocos2d game is to subclass CCNode, add it t
410410

411411
/**
412412
* Expands ( or contracts ) the hit area of the node.
413-
* The expansion is in normalized content size. Ie a hit area expansion of 2, will result in the hit area being double width, and double height.
413+
* The expansion is calculated as a margin around the sprite, in points.
414414
*/
415415
@property (nonatomic, assign) float hitAreaExpansion;
416416

cocos2d/CCProgressNode.m

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838

3939
#import "CCTexture_Private.h"
4040

41-
#define kProgressTextureCoordsCount 4
42-
// kProgressTextureCoords holds points {0,1} {0,0} {1,0} {1,1} we can represent it as bits
43-
const char kCCProgressTextureCoords = 0x4b;
44-
45-
@interface CCProgressNode () {
41+
@implementation CCProgressNode {
4642
CCProgressNodeType _type;
4743
float _percentage;
4844
CCSprite *_sprite;
@@ -57,15 +53,6 @@ @interface CCProgressNode () {
5753
BOOL _needsUpdateProgress;
5854
}
5955

60-
-(void)updateProgress;
61-
-(void)updateBar;
62-
-(void)updateRadial;
63-
-(void)updateColor;
64-
-(CGPoint)boundaryTexCoord:(char)index;
65-
@end
66-
67-
68-
@implementation CCProgressNode
6956
@synthesize percentage = _percentage;
7057
@synthesize sprite = _sprite;
7158
@synthesize type = _type;
@@ -200,8 +187,6 @@ -(GLKVector2)textureCoordFromAlphaPoint:(CGPoint) alpha
200187
CC_SWAP(alpha.x, alpha.y);
201188
}
202189

203-
// As of 3.1, the x alpha needs to be flipped. Not really sure why.
204-
alpha.x = 1.0 - alpha.x;
205190
return GLKVector2Make(min.x * (1.f - alpha.x) + max.x * alpha.x, min.y * (1.f - alpha.y) + max.y * alpha.y);
206191
}
207192

@@ -271,6 +256,13 @@ -(void)setMidpoint:(CGPoint)midPoint
271256
_midpoint = ccpClamp(midPoint, CGPointZero, ccp(1,1));
272257
}
273258

259+
static inline CGPoint
260+
BoundryTexCoord(int index)
261+
{
262+
static const CGPoint points[] = {{1,1}, {1,0}, {0,0}, {0,1}};
263+
return points[index];
264+
}
265+
274266
///
275267
// Update does the work of mapping the texture onto the triangles
276268
// It now doesn't occur the cost of free/alloc data every update cycle.
@@ -317,11 +309,11 @@ -(void)updateRadial
317309

318310
float min_t = FLT_MAX;
319311

320-
for (int i = 0; i <= kProgressTextureCoordsCount; ++i) {
321-
int pIndex = (i + (kProgressTextureCoordsCount - 1))%kProgressTextureCoordsCount;
312+
for (int i = 0; i <= 4; ++i) {
313+
int pIndex = (i + 3)%4;
322314

323-
CGPoint edgePtA = [self boundaryTexCoord:i % kProgressTextureCoordsCount];
324-
CGPoint edgePtB = [self boundaryTexCoord:pIndex];
315+
CGPoint edgePtA = BoundryTexCoord(i % 4);
316+
CGPoint edgePtB = BoundryTexCoord(pIndex);
325317

326318
// Remember that the top edge is split in half for the 12 o'clock position
327319
// Let's deal with that here by finding the correct endpoints
@@ -391,7 +383,7 @@ -(void)updateRadial
391383
_verts[1].position = [self vertexFromAlphaPoint:topMid];
392384

393385
for(int i = 0; i < index; ++i){
394-
CGPoint alphaPoint = [self boundaryTexCoord:i];
386+
CGPoint alphaPoint = BoundryTexCoord(i);
395387
_verts[i+2].texCoord1 = [self textureCoordFromAlphaPoint:alphaPoint];
396388
_verts[i+2].position = [self vertexFromAlphaPoint:alphaPoint];
397389
}
@@ -504,18 +496,6 @@ -(void)updateBar
504496
[self updateColor];
505497
}
506498

507-
-(CGPoint)boundaryTexCoord:(char)index
508-
{
509-
if (index < kProgressTextureCoordsCount) {
510-
if (_reverseDirection) {
511-
return ccp((kCCProgressTextureCoords>>(7-(index<<1)))&1,(kCCProgressTextureCoords>>(7-((index<<1)+1)))&1);
512-
} else {
513-
return ccp((kCCProgressTextureCoords>>((index<<1)+1))&1,(kCCProgressTextureCoords>>(index<<1))&1);
514-
}
515-
}
516-
return CGPointZero;
517-
}
518-
519499
-(void)visit:(CCRenderer *)renderer parentTransform:(const GLKMatrix4 *)parentTransform
520500
{
521501
[super visit:renderer parentTransform:parentTransform];

cocos2d/CCSpriteFrame.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#import "CCSpriteFrameCache.h"
3434

3535
@implementation CCSpriteFrame
36+
{
37+
__weak CCTexture *_lazyTexture;
38+
}
39+
3640
@synthesize textureFilename = _textureFilename;
3741
@synthesize rotated = _rotated;
3842

@@ -137,15 +141,18 @@ -(void) setTexture:(CCTexture *)texture
137141
}
138142
}
139143

140-
-(CCTexture*) texture
144+
-(CCTexture *)lazyTexture
141145
{
142-
if( _texture )
143-
return _texture;
144-
145-
if( _textureFilename )
146-
return [[CCTextureCache sharedTextureCache] addImage:_textureFilename];
146+
CCTexture *texture = _lazyTexture;
147+
if(!texture && _textureFilename){
148+
_lazyTexture = texture = [[CCTextureCache sharedTextureCache] addImage:_textureFilename];
149+
}
150+
151+
return texture;
152+
}
147153

148-
// no texture or texture filename
149-
return nil;
154+
-(CCTexture*) texture
155+
{
156+
return (_texture ?: self.lazyTexture);
150157
}
151158
@end

cocos2d/Platforms/CCGL.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ static inline void __CC_CHECK_GL_ERROR_DEBUG(const char *function, int line)
6262
#define CC_CHECK_GL_ERROR_DEBUG()
6363
#endif
6464

65+
__attribute__((deprecated)) static const GLenum CC_BLEND_SRC = GL_ONE;
66+
__attribute__((deprecated)) static const GLenum CC_BLEND_DST = GL_ONE_MINUS_SRC_ALPHA;
67+
6568
// iOS
6669
#if __CC_PLATFORM_IOS
6770
#define glClearDepth glClearDepthf

cocos2d/ccMacros.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,21 @@ CCRANDOM_ON_UNIT_CIRCLE()
132132
/** @def CC_DEGREES_TO_RADIANS
133133
converts degrees to radians
134134
*/
135-
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
135+
static inline float
136+
CC_DEGREES_TO_RADIANS(const float angle)
137+
{
138+
return angle*0.01745329252f;
139+
}
136140

137141
/** @def CC_RADIANS_TO_DEGREES
138142
converts radians to degrees
139143
*/
140-
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f) // PI * 180
144+
static inline float
145+
CC_RADIANS_TO_DEGREES(const float angle)
146+
{
147+
return angle*57.29577951f;
148+
}
149+
141150

142151

143152
/** @def CC_CONTENT_SCALE_FACTOR

cocos2d/ccTypes.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,14 @@ static inline CCSizeType CCSizeTypeMake(CCSizeUnit widthUnit, CCSizeUnit heightU
468468
return cst;
469469
}
470470

471-
#define CCPositionTypePoints CCPositionTypeMake(CCPositionUnitPoints, CCPositionUnitPoints, CCPositionReferenceCornerBottomLeft)
471+
static const CCPositionType CCPositionTypePoints = {CCPositionUnitPoints, CCPositionUnitPoints, CCPositionReferenceCornerBottomLeft};
472+
static const CCPositionType CCPositionTypeUIPoints = {CCPositionUnitUIPoints, CCPositionUnitUIPoints, CCPositionReferenceCornerBottomLeft};
473+
static const CCPositionType CCPositionTypeNormalized = {CCPositionUnitNormalized, CCPositionUnitNormalized, CCPositionReferenceCornerBottomLeft};
472474

473-
#define CCPositionTypeUIPoints CCPositionTypeMake(CCPositionUnitUIPoints, CCPositionUnitUIPoints, CCPositionReferenceCornerBottomLeft)
474475

475-
#define CCPositionTypeNormalized CCPositionTypeMake(CCPositionUnitNormalized, CCPositionUnitNormalized, CCPositionReferenceCornerBottomLeft)
476-
477-
478-
#define CCSizeTypePoints CCSizeTypeMake(CCSizeUnitPoints, CCSizeUnitPoints)
479-
#define CCSizeTypeUIPoints CCSizeTypeMake(CCSizeUnitUIPoints, CCSizeUnitUIPoints)
480-
#define CCSizeTypeNormalized CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitNormalized)
476+
static const CCSizeType CCSizeTypePoints = {CCSizeUnitPoints, CCSizeUnitPoints};
477+
static const CCSizeType CCSizeTypeUIPoints = {CCSizeUnitUIPoints, CCSizeUnitUIPoints};
478+
static const CCSizeType CCSizeTypeNormalized = {CCSizeUnitNormalized, CCSizeUnitNormalized};
481479

482480
typedef NS_ENUM(char, CCScaleType) {
483481
CCScaleTypePoints,

0 commit comments

Comments
 (0)