Skip to content

Commit

Permalink
Completed #3 items now flow properly across 4 inch iPhone
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdguru committed Mar 6, 2013
1 parent 43421c1 commit fa28a8d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 66 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RDET2/AWHScaleManager.m"
timestampString = "384223797.861577"
timestampString = "384246505.813005"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "45"
endingLineNumber = "45"
startingLineNumber = "50"
endingLineNumber = "50"
landmarkName = "-init"
landmarkType = "5">
</FileBreakpoint>
Expand All @@ -21,11 +21,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "RDET2/AWHScaleManager.m"
timestampString = "384225369.55881"
timestampString = "384246505.813005"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
startingLineNumber = "70"
endingLineNumber = "70"
landmarkName = "-init"
landmarkType = "5">
</FileBreakpoint>
Expand Down
6 changes: 4 additions & 2 deletions RDET2/AWHScaleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
{
BOOL iPad;
BOOL retina;
float width;
float height;
float screenWidth;
float screenHeight;
float paddingWidth;
float paddingHeight;
}
+(id)sharedScaleManager;
-(CGPoint)scalePointX:(float)x andY:(float)y;
Expand Down
85 changes: 30 additions & 55 deletions RDET2/AWHScaleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,31 @@ -(id) init
NSLog(@"retina: NO");
}

//and now we grab the device model
// Get dimensions accounting for autorotation
CGSize size = [[CCDirector sharedDirector] winSize];
screenWidth = size.height;
screenHeight = size.width;

//and now we grab the device model and compute padding widths assuming aspect ratios stay constant
NSString* valueDevice = [[UIDevice currentDevice] model];
if ([valueDevice rangeOfString:@"iPad"].location == NSNotFound)
//Test to see if our valueDevice NSString does not contains the substring iPad & if it does not it is an iPhone otherwise it is an iPad
//Test to see if our valueDevice NSString does not contains the substring iPad & if it does not it is an iPhone otherwise it is an iPad
{
iPad = NO;
NSLog(@"iPad: NO");
paddingWidth = (screenWidth-480)/2;
paddingHeight = (screenHeight-320)/2;
} else {
iPad = YES;
NSLog(@"iPad: YES");
paddingWidth = (screenWidth - 960) / 2;
paddingHeight = (screenHeight - 640) / 2;
}

// Get dimensions accounting for autorotation
CGSize size = [[CCDirector sharedDirector] winSize];
width = size.height;
NSLog( @"Width: %f", width);
height = size.width;
NSLog( @"Height: %f", height);
NSLog( @"Width: %f", screenWidth);
NSLog( @"Padding Width: %f", paddingWidth);
NSLog( @"Height: %f", screenHeight);
NSLog( @"Padding Height: %f", paddingHeight);
}
return self;
}
Expand All @@ -68,39 +75,11 @@ -(id) init
-(CGPoint)scalePointX:(float)x andY:(float)y {
if (!iPad)
// Regardless of actual height/width iPhone base coords in Cocos2d is 480x320
return ccp(x+(width-480)/2,y + (height-320)/2);
return ccp(x+paddingWidth,y + paddingHeight);
else {
// Regardless of actual height/width iPad base coords in Cocos2d is 960x640
float xOffset = (width - 960) / 2;
float yOffset = (height - 640) / 2;
return ccp(2*x+xOffset, 2*y+yOffset);
}

/*
NSLog(@"X: %f", x);
NSLog(@"Y: %f", y);
NSLog( @"Width: %f", width);
NSLog( @"Height: %f", height);
// First detect the original 3.5" iPhone case
if((width == 480) && (height == 320))
return ccp(x,y);
// 4" iPhone case
if(height == 320) {
NSLog(@"Width = 480 case");
return ccp(x+(width-480)/2,y + (height-320)/2);
return ccp(2*x+paddingWidth, 2*y+paddingHeight);
}
CGSize size = [[CCDirector sharedDirector] winSize];
*/


//NSLog(@"xOffset: %f", xOffset);
//NSLog(@"yOffset: %f", yOffset);
//NSLog(@"2*x+xOffset: %f", 2*x+xOffset);
//NSLog(@"2*y+yOffset: %f", 2*y+yOffset);

}

// Enforces font size scaling for iPad vs iPhone
Expand All @@ -117,7 +96,7 @@ -(float)scaleImage {
if (!iPad)
retval = 0.50;

NSLog(@"scaleImage: %f", retval);
//NSLog(@"scaleImage: %f", retval);
return retval;

}
Expand Down Expand Up @@ -175,30 +154,28 @@ -(float)convertDimension:(NSString*)dim ofSprite:(CCSprite*)sprite{
AWHGameStateManager *gameStateManager = [AWHGameStateManager sharedGameStateManager];
if ([dim isEqualToString:@"E"]) {
if (!iPad)
retval = 480;
retval = 480 + paddingWidth;
else {
retval = 480 + (512-480)/2;
retval = 480 + paddingWidth/2;
}
} else if ([dim isEqualToString:@"E+"]) {
if (!iPad)
retval = 480 + [sprite boundingBox].size.width/2;
retval = 480 + paddingWidth + [sprite boundingBox].size.width/2;
else {
retval = 480 + (512-480)/2 + [sprite boundingBox].size.width/4;
retval = 480 + paddingWidth/2 + [sprite boundingBox].size.width/4;
}
//NSLog(@"In Convert Dimension E+: %f width: %f", retval, [sprite boundingBox].size.width);
} else if ([dim isEqualToString:@"W"]) {
if (!iPad)
retval = 0;
retval = -1 * paddingWidth;
else {
retval = -1 * (512-480)/2;
retval = -1 * paddingWidth/2;
}
} else if ([dim isEqualToString:@"W-"]) {
if (!iPad)
retval = 0 - [sprite boundingBox].size.width/2;
retval = -1 * paddingWidth - [sprite boundingBox].size.width/2;
else {
retval = -1 * (512-480)/2 - [sprite boundingBox].size.width/2;
retval = -1 * paddingWidth/2 - [sprite boundingBox].size.width/2;
}
//NSLog(@"In Convert Dimension W-: %f width: %f", retval, [sprite boundingBox].size.width);
} else if ([dim isEqualToString:@"RandomY"]) {
int w=[sprite textureRect].size.width/2;
int h=[sprite textureRect].size.height/2;
Expand All @@ -219,9 +196,8 @@ -(float)convertDimension:(NSString*)dim ofSprite:(CCSprite*)sprite{
}
} else if ([dim isEqualToString:@"EScroll"]) {
int numTiles = [self computeNumHorizTiles:[sprite boundingBox].size.width];
CGSize size = [[CCDirector sharedDirector] winSize];
retval = numTiles*[sprite boundingBox].size.width - size.width;
//NSLog(@"Numtiles: %d WinWidth %f SpriteWidth: %f Delta %f", numTiles, size.width, [sprite boundingBox].size.width, retval);
retval = numTiles*[sprite boundingBox].size.width - screenWidth;
NSLog(@"Numtiles: %d WinWidth %f SpriteWidth: %f Delta %f", numTiles, screenWidth, [sprite boundingBox].size.width, retval);
if (!iPad)
retval = 480 + [sprite boundingBox].size.width-retval*2-2;
else {
Expand Down Expand Up @@ -270,9 +246,8 @@ -(float)computeDurationFromSpeed:(NSString*)speed fromX:(float)fx fromY:(float)f

-(int)computeNumHorizTiles:(float)width {
int retval = 0;
CGSize size = [[CCDirector sharedDirector] winSize];
retval = size.width/width;
//NSLog(@"Sprite Width: %f Win width: %f Retval: %d", width, size.width, retval);
retval = screenWidth/width;
NSLog(@"Sprite Width: %f Win width: %f Retval: %d", width, screenWidth, retval+1);
return retval+1;
}

Expand Down
1 change: 1 addition & 0 deletions RDET2/AWHSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
int value;
BOOL beenEaten;
NSString* fileName;
float duration;
}
@property (nonatomic, retain) CCSprite *mySprite;
-(id)initWithDict:(NSDictionary *)spriteDict;
Expand Down
12 changes: 9 additions & 3 deletions RDET2/AWHSprite.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ -(CCAction *)processActions:(NSDictionary *)action {
}
else if ([actionType isEqualToString:@"Rotate"]) {
//NSLog(@"Action processing a %@", actionType);
return [CCRotateBy actionWithDuration:[[action objectForKey:@"Duration"] floatValue] angle:[[action objectForKey:@"Angle"] floatValue]];
if(duration == 0)
// Not also moving in parallel
return [CCRotateBy actionWithDuration:[[action objectForKey:@"Duration"] floatValue] angle:[[action objectForKey:@"Angle"] floatValue]];
else
// Moving in parallel, duration computed
return [CCRotateBy actionWithDuration:duration angle:[[action objectForKey:@"Angle"] floatValue]];
}
else if ([actionType isEqualToString:@"ScaleBy"]) {
//NSLog(@"Action processing a %@", actionType);
Expand Down Expand Up @@ -179,7 +184,7 @@ -(CCAction *)processActions:(NSDictionary *)action {
}

// Compute the duration and create the sprite
float duration;
//float duration;
if ([action objectForKey:@"Duration"]) {
duration = [[action objectForKey:@"Duration"] floatValue ];
} else {
Expand Down Expand Up @@ -253,7 +258,8 @@ -(id)initWithDict:(NSDictionary *)spriteDict
if (self) {

// Initialize the sprite with data from the dict and with the help of the scaleManager
AWHScaleManager *scaleManager = [AWHScaleManager sharedScaleManager];
AWHScaleManager *scaleManager = [AWHScaleManager sharedScaleManager];
duration = 0;
fileName = [spriteDict objectForKey:@"Name"];
self.mySprite=[CCSprite spriteWithSpriteFrameName:fileName];
mySprite.scale = [scaleManager scaleImage];
Expand Down
26 changes: 26 additions & 0 deletions RDET2/Resources.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@
</dict>
</dict>
</dict>
<dict>
<key>Name</key>
<string>rocky01.png</string>
<key>PositionX</key>
<string>E</string>
<key>PositionY</key>
<string>65</string>
<key>Action</key>
<dict>
<key>ActionType</key>
<string>RepeatForever</string>
<key>ChildAction</key>
<dict>
<key>ActionType</key>
<string>Animate</string>
<key>Sequence</key>
<string>rocky%02d.png</string>
<key>NumFrames</key>
<string>2</string>
<key>Delay</key>
<string>0.5</string>
<key>RestoreOriginalFrame</key>
<false/>
</dict>
</dict>
</dict>
<dict>
<key>Name</key>
<string>start01.png</string>
Expand Down

0 comments on commit fa28a8d

Please sign in to comment.