Tuesday, 16 October 2012

Set the background color to the cclayer in cocos2d + iPhone

//write it inside the init method of cclayer
CCLayerColor* colorLayer = [CCLayerColor layerWithColor:ccc4(128, 0,0, 128)];
[self addChild:colorLayer z:0];

Moving the background image with ccsprite in cocos2d + iPhone

panorama = [CCSprite spriteWithFile: @"blue_drops_2-wallpaper-2048x1152.jpg"];
        panorama.position = ccp( 480/2 , 320/2 );
        [self addChild:panorama];
       
        appendix = [CCSprite spriteWithFile: @"xmas_0020.jpg"];
        appendix.position = ccp( 480/2-1, 320/2 );
        [self addChild:appendix];
       
        // schedule a repeating callback on every frame
        [self schedule:@selector(nextFrame:) interval:.5f];
- (void) nextFrame:(ccTime)dt {
    panorama.position = ccp(panorama.position.x - 100 * dt, panorama.position.y);
    appendix.position = ccp(appendix.position.x - 100 * dt, appendix.position.y);
    if (panorama.position.x < -1709/2) {
        panorama.position = ccp( 1709/2 , panorama.position.y );
        appendix.position = ccp( 1709+480/2-1, appendix.position.y );
    }
}

Scrollview with drag able grid view in iPhone

https://github.com/jaydee3/JDDroppableView

Load json data in lazy loading manner in iphone

- (void)loadDataSource {
    // Request
    NSString *URLPath = [NSString stringWithFormat:@"http://imgur.com/gallery.json"];
    NSURL *URL = [NSURL URLWithString:URLPath];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
   
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
       
        NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];
       
        if (!error && responseCode == 200) {
            id res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            if (res && [res isKindOfClass:[NSDictionary class]]) {
                self.items = [res objectForKey:@"gallery"];
                [self dataSourceDidLoad];
            } else {
                [self dataSourceDidError];
            }
        } else {
            [self dataSourceDidError];
        }
    }];
}

Popover view in iPhone and iPad

https://github.com/runway20/PopoverView

different example for the cocoa2d in iPhone

http://www.supersuraccoon-cocos2d.com/2011/09/17/sticky-demo-resource-list-keep-updating/

Cocos2d calendar demo for iPhone

http://www.supersuraccoon-cocos2d.com/2011/06/05/simple-calendar-demo-cocos2d/