This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: http://blog.mbcharbonneau.com/post/56581688/better-logging-in-objective-c | |
#define DebugLog(format, ...) NSLog(@"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GCC Attribute for autoscoped Obj-C objects | |
// Source: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/13/232287 | |
#define autoscoped __attribute__((cleanup(releaseObject))) | |
static inline void releaseObject(id *object) | |
{ | |
[*object release]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSObject+BlockObservation.h | |
// Version 1.0 | |
// | |
// Andy Matuschak | |
// andy@andymatuschak.org | |
// Public domain because I love you. Let me know how you use it. | |
// | |
#import <Cocoa/Cocoa.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { | |
UITouch * touch = [touches anyObject]; | |
CGPoint location = [[Director sharedDirector] convertCoordinate: [touch locationInView:touch.view]]; | |
CGRect myRect = CGRectMake(sprite.position.x, sprite.position.y, sprite.contentSize.width, sprite.contentSize.height); | |
if(CGRectContainsPoint(myRect, location)) { | |
// particularSprite touched | |
return kEventHandled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
glEnable(GL_SCISSOR_TEST); | |
// Some region to clip to | |
CGRect rect = CGRect(100, 100, 200, 200); | |
CGRect frame = [[[CCDirector sharedDirector] openGLView] frame]; | |
// Adjust for position | |
CGPoint worldPos = [self convertToWorldSpaceAR:position_]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle | |
{ | |
CGFloat angleInRadians = angle * (M_PI / 180); | |
CGFloat width = CGImageGetWidth(imgRef); | |
CGFloat height = CGImageGetHeight(imgRef); | |
CGRect imgRect = CGRectMake(0, 0, width, height); | |
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians); | |
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id) init | |
{ | |
if( (self=[super init] )) { | |
CGSize size = [[CCDirector sharedDirector] winSize]; | |
CCTexture2D *bg = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"Default.png"]]; | |
CCSprite *staticBackground0 = [CCSprite spriteWithTexture:bg]; | |
staticBackground0.position = ccp(-size.width/2,size.height/2); | |
CCSprite *staticBackground1 = [CCSprite spriteWithTexture:bg]; | |
staticBackground1.position = ccp(size.width/2,size.height/2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CCSpriteSheet *animationSheet = [CCSpriteSheet spriteSheetWithFile:@"animation_sheet.png"]; | |
[self addChild:animationSheet]; | |
CCSprite *animationSprite = [CCSprite spriteWithTexture:animationSheet.texture | |
rect:CGRectMake(0, 0, 256, 290)]; | |
animationSprite.position = ccp(self.contentSize.width / 2, self.contentSize.height / 2); | |
[animationSheet addChild:animationSprite]; | |
CCAnimation *animation = [CCAnimation animationWithName:@"an_animation" delay:0.04f]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSObject(Swizzle) | |
+ (void)swizzleMethod:(SEL)orig_sel withMethod:(SEL)alt_sel; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make button block. | |
UIBarButtonItem* (^buttonWithTitle)(NSString*, SEL) = ^(NSString* title, SEL action) | |
{ | |
UIBarButtonItem* button = [UIBarButtonItem alloc]; | |
[button initWithTitle:title | |
style:UIBarButtonItemStyleBordered | |
target:self | |
action:action]; | |
[button setWidth:65.0f]; | |
[button autorelease]; |
OlderNewer