Skip to content

Instantly share code, notes, and snippets.

View sdabet's full-sized avatar

Sébastien Dabet sdabet

  • Grenoble, France
View GitHub Profile
@implementation NodeRenderer
+(id)renderTextureWithNode:(CCNode*)node width:(int)w height:(int)h
{
return [[[self alloc] initWithNode:node width:w height:h pixelFormat:kCCTexture2DPixelFormat_RGBA8888 depthStencilFormat:0] autorelease];
}
-(id) initWithNode:(CCNode*)n width:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat)format depthStencilFormat:(GLuint)depthStencilFormat {
if(self = [super initWithWidth:w height:h pixelFormat:format]) {
[self addChild:n];
@implementation CustomScrollLayer
@synthesize customPageIndicators;
+(id) nodeWithLayers:(NSArray *)layers widthOffset: (int) widthOffset pageSpriteFrameName:(NSString*)pageSpriteFrameName
{
return [[[self alloc] initWithLayers: layers widthOffset:widthOffset pageSpriteFrameName:pageSpriteFrameName] autorelease];
}
/*
@interface CustomScrollLayer : CCScrollLayer
@property (nonatomic, retain) CCNode *customPageIndicators;
+(id) nodeWithLayers:(NSArray *)layers widthOffset:(int)widthOffset pageSpriteFrameName:(NSString*)pageSpriteFrameName;
-(id) initWithLayers:(NSArray *)layers widthOffset:(int)widthOffset pageSpriteFrameName:(NSString*)pageSpriteFrameName;
@end
navController_ = [[LandscapeNavigationController alloc] initWithRootViewController:director_];
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
#import "LandscapeNavigationController.h"
@implementation LandscapeNavigationController
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
#import <UIKit/UIKit.h>
@interface LandscapeNavigationController : UINavigationController
@end
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
CCNode *node = [CCNode node];
[node addChild:child1];
[node addChild:child2];
// ...
[node centerContentWithPadding:10 TotalWidth:[[CCDirector sharedDirector] winSize].width];
@implementation CCNode (centering)
-(void) centerContentWithPadding:(int)padding TotalWidth:(int)totalWidth{
int contentWidth = 0;
for(int i=0; i < self.children.count; i++) {
CCNode *child = [self.children objectAtIndex:i];
contentWidth += child.contentSize.width;
}
int currentX = (totalWidth - contentWidth) / 2;