Skip to content

Instantly share code, notes, and snippets.

View sdabet's full-sized avatar

Sébastien Dabet sdabet

  • Grenoble, France
View GitHub Profile
bool test = true;
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@sdabet
sdabet / gist:4327634
Created December 18, 2012 12:42
Game Center authentication for both iOS 5 and iOS 6
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
// iOS 6
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil)
{
[navController_ presentViewController:viewController animated:false completion:nil];
}
#import "CCScrollLayer.h"
@interface ElasticScrollLayer : CCScrollLayer
@property float actionDuration, bouncePeriod;
+(id) nodeWithLayers:(NSArray *)layers widthOffset: (int) widthOffset actionDuration:(float)duration bouncePeriod:(float)period;
@end
@sdabet
sdabet / gist:4327693
Created December 18, 2012 12:51
ElasticScrollLayer.m
#import "ElasticScrollLayer.h"
@implementation ElasticScrollLayer
@synthesize actionDuration, bouncePeriod;
+(id) nodeWithLayers:(NSArray *)layers widthOffset: (int) widthOffset actionDuration:(float)duration bouncePeriod:(float)period
{
ElasticScrollLayer *layer = [[[self alloc] initWithLayers: layers widthOffset:widthOffset] autorelease];
layer.actionDuration = duration;
@sdabet
sdabet / gist:4335168
Created December 19, 2012 08:00
Item.h
@interface Item : NSObject
+(id) itemWithNode:(CCNode*)node;
-(id) initWithNode:(CCNode*)node;
// The view
@property (nonatomic, retain) CCNode *node;
// "Forwarding" stuff
@property (nonatomic,readwrite,assign) CGPoint position;
@sdabet
sdabet / gist:4460736
Last active December 10, 2015 16:28
Header of ScalableMenuItemImage. Just provide some convenience constructors
@interface ScalableMenuItemImage : CCMenuItemImage
+(id) itemWithNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 target:(id) t selector:(SEL) s;
+(id) itemWithNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block;
@end
@sdabet
sdabet / gist:4460746
Last active December 10, 2015 16:28
Implementation of ScalableMenuItemImage
@implementation ScalableMenuItemImage
+(id) itemWithNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3 target:(id) t selector:(SEL) s {
return [[[self alloc] initWithNormalImage:value selectedImage:value2 disabledImage:value3 target:t selector:s] autorelease];
}
+(id) itemWithNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block {
return [[[self alloc] initWithNormalImage:value selectedImage:value2 disabledImage:value3 block:block] autorelease];
}
@interface CCNode (centering)
-(void) centerContentWithPadding:(int)padding TotalWidth:(int)totalWidth;
@end
@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;