Monday, 29 July 2013

To hide frame stats in cocos2d




[[CCDirector sharedDirector] setDisplayStats:NO];


To create screen bound in cocos2d chipmunk

#define PhysicsIdentifier(key) ((__bridge id)(void *)(@selector(key)))


CGSize winSize = [CCDirector sharedDirector].winSize;
        CGRect rect = {CGPointZero, winSize};
        [_space addBounds:rect
                thickness:8.0f
               elasticity:1.0f friction:1.0f
                   layers:CP_ALL_LAYERS group:CP_NO_GROUP
            collisionType:PhysicsIdentifier(COLLISION_TYPE_TERRAIN)

         ];

Thursday, 25 July 2013

To resize or scale UIView

CGFloat dWidth = [[UIScreen mainScreen]bounds].size.width;
CGFloat dHeight = [[UIScreen mainScreen]bounds].size.height;
            
CGAffineTransform transform;
transform = CGAffineTransformMakeScale(dWidth/urView.bounds.size.width, dHeight/urView.bounds.size.height);

dHeight.transform = transform;

Thursday, 18 July 2013

Convert UIImage to CCSprite




 CCSprite*  sprite = [[[CCSprite alloc] initWithCGImage: [urUIImage CGImage] key: @"SomeUniqueReferenceNameForThisSprite"] autorelease];


To find Specific CCSprite from a sprite-sheet using plist



[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"playerSS.plist"];   // plist name
    NSString *frameName = [NSString stringWithFormat:@"a%04i.png",10]; 

 // sprite names leg. a0001 -- a000n.png


   //[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName];
 CCSprite *arm2 = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];

Wednesday, 17 July 2013

To Disable touch of all CCMenu items or sub nodes on a CCLayer

Call below methods as needed:

[self MenuStatus:NO Node:self]; // to disable touch 

[self MenuStatus:YES Node:self]; // to enable touch


Method:

-(void)MenuStatus:(BOOL)_enable Node:(id)_node
{
    for (id result in ((CCNode *)_node).children) {
        if ([result isKindOfClass:[CCMenu class]]) {
            for (id result1 in ((CCMenu *)result).children) {
                if ([result1 isKindOfClass:[CCMenuItem class]]) {
                    ((CCMenuItem *)result1).isEnabled = _enable;
                }
            }
        }
        else
            [self MenuStatus:_enable Node:result];
    }

}


Friday, 12 July 2013

cocos2d breathing effect and animate up and down on a Sprite



id Item1Down= [CCMoveBy actionWithDuration:2.5 position:ccp(0,-15)];
id Item1Up= [CCMoveBy actionWithDuration:2.5 position:ccp(0,+15)];
id easeDown1 = [CCEaseInOut actionWithAction: Item1Down rate:2];
id easeDown2 = [CCEaseInOut actionWithAction: Item1Up rate:2];
id sequence = [CCSequence actionOne: easeDown1 two: easeDown2];

[yourSprite runAction:[CCRepeatForever actionWithAction: sequence]];



UILabel Text Width xcode



[[urLabel text] sizeWithFont:[urLabel font]].width

Thursday, 11 July 2013

Animation png sequence in cocos2d by plist

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"toon.plist"];
        
 CCSprite *cartoon = [CCSprite spriteWithSpriteFrameName:@"a0001.png"];
 cartoon.position = ccp(s.width/2,s.height/2);
[self addChild: cartoon];
        
NSMutableArray *frames = [[NSMutableArray alloc] init];
for (int i = 1; i <= 10; i++) 
{
NSString *frameName = [NSString stringWithFormat:@"a%04i.png",i];
[frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
        
CCAnimation *a = [CCAnimation animationWithFrames:frames delay:1.0f/24.0f];

[cartoon runAction:[CCAnimate actionWithAnimation:a restoreOriginalFrame:NO]];

Wednesday, 10 July 2013

To customize Facebook Login View with custom image



 FBLoginView *loginview = [[FBLoginView alloc] init];
        for (id loginObject in loginview.subviews)
        {
            if ([loginObject isKindOfClass:[UIButton class]])
            {
                UIButton * loginButton =  loginObject;
                UIImage *loginImage = [UIImage imageNamed:@"f connect.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
               
            }
            if ([loginObject isKindOfClass:[UILabel class]])
            {
                UILabel * loginLabel =  loginObject;
                loginLabel.text = @"";
                loginLabel.frame = CGRectMake(0, 0, 0, 0);
            }
        }
        
        loginview.frame = CGRectMake(5, 5, 150, 400);

        loginview.delegate = self;
        [self.view addSubview:loginview];

To add a UIView in COCOS2D Layer


  [[[CCDirector sharedDirector] view] addSubview:myView];

Tuesday, 2 July 2013

To know UIFont list



 NSLog(@"Fonts \n%@",[UIFont familyNames]);

Output:

Fonts
(
    Thonburi,
    "Snell Roundhand",
    "Academy Engraved LET",
    "Marker Felt",
    "Geeza Pro",
    "Arial Rounded MT Bold",
    "Trebuchet MS",
    Arial,
    Marion,
    "Gurmukhi MN",
    "Malayalam Sangam MN",
    "Bradley Hand",
    "Kannada Sangam MN",
    "Bodoni 72 Oldstyle",
    Cochin,
    "Sinhala Sangam MN",
    "Hiragino Kaku Gothic ProN",
    "Cronos Pro",
    Papyrus,
    Verdana,
    "Zapf Dingbats",
    Courier,
    "Hoefler Text",
    "Euphemia UCAS",
    Helvetica,
    "Hiragino Mincho ProN",
    "Bodoni Ornaments",
    "Apple Color Emoji",
    Optima,
    "Gujarati Sangam MN",
    "Devanagari Sangam MN",
    "Times New Roman",
    Kailasa,
    "Telugu Sangam MN",
    "Heiti SC",
    Futura,
    "Bodoni 72",
    Baskerville,
    "Chalkboard SE",
    "Heiti TC",
    Copperplate,
    "Party LET",
    "American Typewriter",
    AppleGothic,
    "Bangla Sangam MN",
    Noteworthy,
    Zapfino,
    "Tamil Sangam MN",
    "DB LCD Temp",
    "Arial Hebrew",
    Chalkduster,
    Georgia,
    "Helvetica Neue",
    "Gill Sans",
    Palatino,
    "Courier New",
    "Oriya Sangam MN",
    Didot,
    "Bodoni 72 Smallcaps"
)