summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-09-05 14:20:31 -0400
committerStarla Insigna <starla4444@gmail.com>2011-09-05 14:20:31 -0400
commita9f61d5df9bd2a9fec365ba7110e5ec09148cf1a (patch)
treeea634b5c4800f5b6f13518f480b4a5bb55d00d39
parent1cdf1d1424d869a2969fc2a1859e337086f086d5 (diff)
downloadcartcollect-a9f61d5df9bd2a9fec365ba7110e5ec09148cf1a.tar.gz
cartcollect-a9f61d5df9bd2a9fec365ba7110e5ec09148cf1a.tar.bz2
cartcollect-a9f61d5df9bd2a9fec365ba7110e5ec09148cf1a.zip
Jump: Fixed zero-width ledge bug
While this had no affect on the player, the game would sometimes randomly generate zero-width ledges when spawning ledges, which caused a whole ton of problems with the graphic generation and CCTexture2D and was the reason that the console was spammed with so many error messages when nothing bad seemed to be happening. The game would output the errors, drop the zero-width ledge and continue on as if nothing had happened.

Fixes #217
-rw-r--r--Classes/JumpGameMode.m6
1 files changed, 5 insertions, 1 deletions
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 13294c3..93e05ea 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m
@@ -129,7 +129,8 @@
129 129
130 if (rightmost <= 480) 130 if (rightmost <= 480)
131 { 131 {
132 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:(arc4random() % 10) height:2]]; 132 int ledgeWidth = arc4random() % 9 + 1;
133 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]];
133 CCSprite* ledge = [CCSprite spriteWithTexture:texture]; 134 CCSprite* ledge = [CCSprite spriteWithTexture:texture];
134 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64, 32); 135 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64, 32);
135 [self addChild:ledge]; 136 [self addChild:ledge];
@@ -463,6 +464,9 @@
463 464
464- (UIImage*)createLedgeWithWidth:(int)width height:(int)height 465- (UIImage*)createLedgeWithWidth:(int)width height:(int)height
465{ 466{
467 NSAssert(width > 0, @"Ledge width must be greater than 0");
468 NSAssert(height > 0, @"Ledge height must be greater than 0");
469
466 UIGraphicsBeginImageContext(CGSizeMake(width*32, height*32)); 470 UIGraphicsBeginImageContext(CGSizeMake(width*32, height*32));
467 471
468 for (int y=0; y<height; y++) 472 for (int y=0; y<height; y++)