2010년 11월 30일 화요일

CCLabel multiline

        // Define your text
NSString *txt = @"Your text here, no need to add breaklines, but if you want to break in a particular point, use \n and it will go to next line...";
//  Measure the height of the string given the width.
float fontSize = 14;
CGSize maxSize = { 300, 200 }; // Start off with an actual width and a height.
// Calculate the actual size of the text with the font, size and line break mode.
CGSize actualSize = [txt sizeWithFont:[UIFont fontWithName:@"Trebuchet MS" size:fontSize]
constrainedToSize:maxSize
lineBreakMode:UILineBreakModeWordWrap];
CGSize containerSize = { actualSize.width, actualSize.height };
CCLabel* label = [CCLabel labelWithString:txt
  dimensions:containerSize
alignment:UITextAlignmentLeft
fontName:@"Trebuchet MS"
fontSize:fontSize];
label.anchorPoint = CGPointZero;
label.position = ccp(100,100);
[self addChild:label z:1000];

UIImage 이미지 자른 후 다른 이미지와 합치기

 //get character image
CGImageRef tmp = CGImageCreateWithImageInRect( [_uc.image CGImage], CGRectMake(0, 28, 100, 95)); 
UIImage *_character = [UIImage resizeImage:[UIImage imageWithCGImage:tmp] width:72 height:72];
UIImage *_bg = [UIImage imageNamed:@"characterbox_bg.png"];
//combine background image + character image
UIGraphicsBeginImageContext(_bg.size);
[_bg drawInRect:CGRectMake(0, 0, _bg.size.width, _bg.size.height)];
[_character drawInRect:CGRectMake(0, 0, _character.size.width, _character.size.height)];
UIImage *_result_img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


=======================================================================


CCSprite *sprite =  [CCSprite spriteWithTexture:
 [[CCTexture2D alloc] initWithImage:
  [_u.image imageByScalingAndCroppingForSize:CGSizeMake(95, 95) withTargetPoint:CGPointMake(5, 5)]]];