Skip to content

Commit

Permalink
retina support added
Browse files Browse the repository at this point in the history
  • Loading branch information
haqu committed Dec 18, 2011
1 parent d513224 commit 634e35a
Show file tree
Hide file tree
Showing 34 changed files with 5,501 additions and 24 deletions.
1,429 changes: 1,429 additions & 0 deletions tiny-wings-mac.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tiny-wings-mac/Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'cocos2d-mac' target in the 'cocos2d-mac' project
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
2 changes: 2 additions & 0 deletions tiny-wings-mac/Resources/English.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

958 changes: 958 additions & 0 deletions tiny-wings-mac/Resources/English.lproj/MainMenu.xib

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions tiny-wings-mac/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>icon</string>
<key>CFBundleIdentifier</key>
<string>com.iplayful.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Binary file added tiny-wings-mac/Resources/fps_images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tiny-wings-mac/Resources/icon.icns
Binary file not shown.
22 changes: 22 additions & 0 deletions tiny-wings-mac/System/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AppDelegate.h
// tiny-wings-mac
//
// Created by Sergey Tikhonov on 15.12.11.
// Copyright iPlayful Inc. 2011. All rights reserved.
//

#import "cocos2d.h"

@interface tiny_wings_macAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window_;
MacGLView *glView_;
}

@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet MacGLView *glView;

- (IBAction)toggleFullScreen:(id)sender;

@end
54 changes: 54 additions & 0 deletions tiny-wings-mac/System/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// AppDelegate.m
// tiny-wings-mac
//
// Created by Sergey Tikhonov on 15.12.11.
// Copyright iPlayful Inc. 2011. All rights reserved.
//

#import "AppDelegate.h"
#import "GameLayer.h"

@implementation tiny_wings_macAppDelegate
@synthesize window=window_, glView=glView_;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];

[director setDisplayFPS:YES];

[director setOpenGLView:glView_];

// EXPERIMENTAL stuff.
// 'Effects' don't work correctly when autoscale is turned on.
// Use kCCDirectorResize_NoScale if you don't want auto-scaling.
[director setResizeMode:kCCDirectorResize_AutoScale];

// Enable "moving" mouse event. Default no.
[window_ setAcceptsMouseMovedEvents:NO];

[director runWithScene:[GameLayer scene]];
}

- (BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication *) theApplication
{
return YES;
}

- (void)dealloc
{
[[CCDirector sharedDirector] end];
[window_ release];
[super dealloc];
}

#pragma mark AppDelegate - IBActions

- (IBAction)toggleFullScreen: (id)sender
{
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
[director setFullScreen: ! [director isFullScreen] ];
}

@end
17 changes: 17 additions & 0 deletions tiny-wings-mac/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// main.m
// cocos2d-mac
//
// Created by Ricardo Quesada on 8/17/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "cocos2d.h"

int main(int argc, char *argv[])
{
[MacGLView load_];
return NSApplicationMain(argc, (const char **) argv);
}
14 changes: 13 additions & 1 deletion tiny-wings.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
4D20B98F149D991100B1451D /* hero-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D20B98C149D991100B1451D /* hero-hd.png */; };
4D20B990149D991100B1451D /* noise-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D20B98D149D991100B1451D /* noise-hd.png */; };
4D20B991149D991100B1451D /* resetButton-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D20B98E149D991100B1451D /* resetButton-hd.png */; };
4D4B4BE813A37A4900A6341D /* LICENSE_Box2D.txt in Resources */ = {isa = PBXBuildFile; fileRef = 4D4B4BE713A37A4900A6341D /* LICENSE_Box2D.txt */; };
4D6FFC25149A3101009512B8 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D6FFC1F149A3101009512B8 /* AppDelegate.mm */; };
4D6FFC26149A3101009512B8 /* GLES-Render.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D6FFC22149A3101009512B8 /* GLES-Render.mm */; };
Expand Down Expand Up @@ -180,6 +183,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4D20B98C149D991100B1451D /* hero-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "hero-hd.png"; sourceTree = "<group>"; };
4D20B98D149D991100B1451D /* noise-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "noise-hd.png"; sourceTree = "<group>"; };
4D20B98E149D991100B1451D /* resetButton-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "resetButton-hd.png"; sourceTree = "<group>"; };
4D4B4BE713A37A4900A6341D /* LICENSE_Box2D.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE_Box2D.txt; path = libs/LICENSE_Box2D.txt; sourceTree = "<group>"; };
4D6FFC1E149A3101009512B8 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4D6FFC1F149A3101009512B8 /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppDelegate.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -580,9 +586,12 @@
4D6FFC38149A3110009512B8 /* Images */ = {
isa = PBXGroup;
children = (
4D6FFC3A149A3110009512B8 /* noise.png */,
4D6FFC39149A3110009512B8 /* hero.png */,
4D20B98C149D991100B1451D /* hero-hd.png */,
4D6FFC3A149A3110009512B8 /* noise.png */,
4D20B98D149D991100B1451D /* noise-hd.png */,
4D6FFC3B149A3110009512B8 /* resetButton.png */,
4D20B98E149D991100B1451D /* resetButton-hd.png */,
);
path = Images;
sourceTree = "<group>";
Expand Down Expand Up @@ -1193,6 +1202,9 @@
4D6FFC42149A3113009512B8 /* good_dog_plain_32.fnt in Resources */,
4D6FFC43149A3113009512B8 /* good_dog_plain_32.png in Resources */,
4D6FFC45149A3125009512B8 /* LICENSE.txt in Resources */,
4D20B98F149D991100B1451D /* hero-hd.png in Resources */,
4D20B990149D991100B1451D /* noise-hd.png in Resources */,
4D20B991149D991100B1451D /* resetButton-hd.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
33 changes: 23 additions & 10 deletions tiny-wings/Game/Objects/Hero.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,25 @@ - (void) dealloc {

- (void) createBox2DBody {

CGPoint startPosition = ccp(0, _game.screenH/2+_radius);

b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.linearDamping = 0.05f;
bd.fixedRotation = true;
bd.position.Set(startPosition.x/PTM_RATIO, startPosition.y/PTM_RATIO);

// start position
CGPoint p = ccp(0, _game.screenH/2+_radius);
p.x /= PTM_RATIO;
p.y /= PTM_RATIO;

// adjust body position for retina
p.x *= CC_CONTENT_SCALE_FACTOR();
p.y *= CC_CONTENT_SCALE_FACTOR();

bd.position.Set(p.x, p.y);
_body = _game.world->CreateBody(&bd);

b2CircleShape shape;
shape.m_radius = _radius/PTM_RATIO;
shape.m_radius = _radius/PTM_RATIO*CC_CONTENT_SCALE_FACTOR();

b2FixtureDef fd;
fd.shape = &shape;
Expand Down Expand Up @@ -133,16 +141,21 @@ - (void) updatePhysics {
}

- (void) updateNode {
float x = _body->GetPosition().x*PTM_RATIO;
float y = _body->GetPosition().y*PTM_RATIO;

CGPoint p = ccp(_body->GetPosition().x, _body->GetPosition().y);
p.x *= PTM_RATIO;
p.y *= PTM_RATIO;

// adjust position for retina
p.x /= CC_CONTENT_SCALE_FACTOR();
p.y /= CC_CONTENT_SCALE_FACTOR();

// CCNode position and rotation
self.position = ccp(x, y);
self.position = p;
b2Vec2 vel = _body->GetLinearVelocity();
float angle = atan2f(vel.y, vel.x);

#ifdef DRAW_BOX2D_WORLD
body->SetTransform(body->GetPosition(), angle);
_body->SetTransform(_body->GetPosition(), angle);
#else
self.rotation = -1 * CC_RADIANS_TO_DEGREES(angle);
#endif
Expand All @@ -160,7 +173,7 @@ - (void) updateNode {
}

// TEMP: sleep if below the screen
if (y < -_radius && _awake) {
if (p.y < -_radius && _awake) {
[self sleep];
}
}
Expand Down
18 changes: 12 additions & 6 deletions tiny-wings/Game/Objects/Sky.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,25 @@ - (CCTexture2D*) generateTexture {
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

CGPoint vertices[4];
ccVertex2F vertices[4];
ccColor4F colors[4];
int nVertices = 0;

vertices[nVertices] = ccp(0, 0);
vertices[nVertices] = (ccVertex2F){0, 0};
colors[nVertices++] = (ccColor4F){1, 1, 1, 0};
vertices[nVertices] = ccp(textureSize, 0);
vertices[nVertices] = (ccVertex2F){textureSize, 0};
colors[nVertices++] = (ccColor4F){1, 1, 1, 0};

vertices[nVertices] = ccp(0, textureSize);
vertices[nVertices] = (ccVertex2F){0, textureSize};
colors[nVertices++] = (ccColor4F){1, 1, 1, gradientAlpha};
vertices[nVertices] = ccp(textureSize, textureSize);
vertices[nVertices] = (ccVertex2F){textureSize, textureSize};
colors[nVertices++] = (ccColor4F){1, 1, 1, gradientAlpha};

// adjust vertices for retina
for (int i=0; i<nVertices; i++) {
vertices[i].x *= CC_CONTENT_SCALE_FACTOR();
vertices[i].y *= CC_CONTENT_SCALE_FACTOR();
}

glVertexPointer(2, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0, colors);
Expand All @@ -106,7 +112,7 @@ - (CCTexture2D*) generateTexture {
CCSprite *s = [CCSprite spriteWithFile:@"noise.png"];
[s setBlendFunc:(ccBlendFunc){GL_DST_COLOR, GL_ZERO}];
s.position = ccp(textureSize/2, textureSize/2);
s.scale = (float)textureSize/512.0f;
s.scale = (float)textureSize/512.0f*CC_CONTENT_SCALE_FACTOR();
glColor4f(1,1,1,1);
[s visit];

Expand Down
45 changes: 43 additions & 2 deletions tiny-wings/Game/Objects/Terrain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ - (void) renderStripes {

}

// adjust vertices for retina
for (int i=0; i<nVertices; i++) {
vertices[i].x *= CC_CONTENT_SCALE_FACTOR();
vertices[i].y *= CC_CONTENT_SCALE_FACTOR();
}

glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

Expand Down Expand Up @@ -211,6 +217,12 @@ - (void) renderGradient {
colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};
}

// adjust vertices for retina
for (int i=0; i<nVertices; i++) {
vertices[i].x *= CC_CONTENT_SCALE_FACTOR();
vertices[i].y *= CC_CONTENT_SCALE_FACTOR();
}

glVertexPointer(2, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0, colors);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
Expand All @@ -235,6 +247,12 @@ - (void) renderHighlight {
vertices[nVertices] = (ccVertex2F){textureSize, highlightWidth};
colors[nVertices++] = (ccColor4F){0, 0, 0, 0};

// adjust vertices for retina
for (int i=0; i<nVertices; i++) {
vertices[i].x *= CC_CONTENT_SCALE_FACTOR();
vertices[i].y *= CC_CONTENT_SCALE_FACTOR();
}

glVertexPointer(2, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0, colors);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Expand All @@ -244,14 +262,20 @@ - (void) renderHighlight {
- (void) renderTopBorder {

float borderAlpha = 0.5f;
float borderWidth = 2.0f;
float borderWidth = 2.0f*CC_CONTENT_SCALE_FACTOR();

ccVertex2F vertices[2];
int nVertices = 0;

vertices[nVertices++] = (ccVertex2F){0, borderWidth/2};
vertices[nVertices++] = (ccVertex2F){textureSize, borderWidth/2};

// adjust vertices for retina
for (int i=0; i<nVertices; i++) {
vertices[i].x *= CC_CONTENT_SCALE_FACTOR();
// vertices[i].y *= CC_CONTENT_SCALE_FACTOR();
}

glDisableClientState(GL_COLOR_ARRAY);

glLineWidth(borderWidth);
Expand All @@ -269,7 +293,7 @@ - (void) renderNoise {
CCSprite *s = [CCSprite spriteWithFile:@"noise.png"];
[s setBlendFunc:(ccBlendFunc){GL_DST_COLOR, GL_ZERO}];
s.position = ccp(textureSize/2, textureSize/2);
s.scale = (float)textureSize/512.0f;
s.scale = (float)textureSize/512.0f*CC_CONTENT_SCALE_FACTOR();
glColor4f(1, 1, 1, 1);
[s visit];
[s visit]; // more contrast
Expand Down Expand Up @@ -311,6 +335,12 @@ - (void) generateHillKeyPoints {
x += minDX+rangeDX;
y = 0;
hillKeyPoints[nHillKeyPoints++] = (ccVertex2F){x, y};

// adjust vertices for retina
for (int i=0; i<nHillKeyPoints; i++) {
hillKeyPoints[i].x *= CC_CONTENT_SCALE_FACTOR();
hillKeyPoints[i].y *= CC_CONTENT_SCALE_FACTOR();
}

fromKeyPointI = 0;
toKeyPointI = 0;
Expand Down Expand Up @@ -340,6 +370,13 @@ - (void) generateBorderVertices {

p0 = p1;
}

// // adjust vertices for retina
// for (int i=0; i<nBorderVertices; i++) {
// borderVertices[i].x *= CC_CONTENT_SCALE_FACTOR();
// borderVertices[i].y *= CC_CONTENT_SCALE_FACTOR();
// }

// CCLOG(@"nBorderVertices = %d", nBorderVertices);
}

Expand Down Expand Up @@ -377,6 +414,10 @@ - (void) resetHillVertices {
float leftSideX = _offsetX-screenW/8/self.scale;
float rightSideX = _offsetX+screenW*7/8/self.scale;

// adjust position for retina
leftSideX *= CC_CONTENT_SCALE_FACTOR();
rightSideX *= CC_CONTENT_SCALE_FACTOR();

while (hillKeyPoints[fromKeyPointI+1].x < leftSideX) {
fromKeyPointI++;
if (fromKeyPointI > nHillKeyPoints-1) {
Expand Down
Loading

0 comments on commit 634e35a

Please sign in to comment.