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
- (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
-(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]; |
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
curl -o .gitignore https://github.com/github/gitignore/raw/master/Objective-C.gitignore |
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
// | |
// AutoEncoder.h | |
// QuartzTest | |
// | |
// Created by Alex Wiltschko on 6/27/11. | |
// Copyright 2011 __MyCompanyName__. All rights reserved. | |
// | |
#import <Foundation/Foundation.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
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { | |
[self.view removeFromSuperview]; | |
} | |
-(void) dismiss { | |
[UIView beginAnimations:nil context:nil]; | |
[UIView setAnimationDuration:0.3f]; | |
[UIView setAnimationDelegate:self]; | |
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; | |
OlderNewer