|
1 |
[labelname setString:@"string"]; |
Cocos2d Archives
Updating labels in cocos2d
How to convert a UIView into a UIImage
To convert uiview into a uiimage ..You can use the following code.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
-(void)takeScreenShot{ UIGraphicsBeginImageContext(certificateView.bounds.size); [certificateView.layer renderInContext:UIGraphicsGetCurrentContext()]; uiimage collageImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [collageImage retain]; } |
How to add email facility in Objective C
To include email facility in your cocos program,you have to add the MessageUI framework in your program.
Then you have to include the following code.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
-(void)sendMail { MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; if(!mailController) { return; } mailController.mailComposeDelegate = self; [mailController setSubject:@"Certificate"]; ///for setting the message subject. [mailController setMessageBody:@"Rate this app if you like it.Find similar products at www.schogini.in ." isHTML:YES];///for setting the message body. [mailController addAttachmentData:UIImageJPEGRepresentation (collageImage,0.5) mimeType:@"image/jpeg" fileName:@"image.jpg"];//for adding an attachmet. //[mailController setCcRecipients:[NSArray arrayWithObjects:@"<a href="mailto:augustine@schogini.com">augustine@schogini.com</a>",nil]];//to set a ccrecipient. UIWindow *topWindow; NSArray *windows = [[UIApplication sharedApplication] windows]; for(topWindow in windows) { if (topWindow.windowLevel == UIWindowLevelNormal) break; } UIView *rootView = [[topWindow subviews] objectAtIndex:0]; id nextResponder = [rootView nextResponder]; UIViewController *rootViewController = nextResponder; while (rootViewController.modalViewController != nil) rootViewController = rootViewController.modalViewController; UIViewController *topViewController = rootViewController; [topViewController presentModalViewController:mailController animated:YES]; } //Also you have to add the mail composer control delegate.. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { switch (result) { case MFMailComposeResultSent: break; case MFMailComposeResultSaved: break; case MFMailComposeResultCancelled: NSLog(@"cancelled....."); break; case MFMailComposeResultFailed: NSLog(@"failed....."); break; } [controller dismissModalViewControllerAnimated:YES]; [controller release]; } |
Multi Touch in Cocos2d
To recieve multi-touch events, you have to activate them. You can do this by adding the following code in your AppDelegate’s applicationDidFinishLaunching:
|
1 |
[glView setMultipleTouchEnabled:YES]; |
To reverse all actions
Almost all actions have the reverse method implemented. Basically it creates a new action with the reverse behavior.
Example:
|
1 2 3 |
id move = [CCMoveBy actionWithDuration:2 position: ccp(80,80)]; id move_reverse = [move reverse]; |
The move_reverse action will be a CCMoveBy action of duration 2, but with the position value of ccp(-80,-80).
To pause/resume all actions
|
1 2 3 4 5 |
// Pause actions [[CCActionManager sharedManager ] pauseAllActionsForTarget:sprite ] ; // resume actions [[CCActionManager sharedManager ] resumeAllActionsForTarget:sprite ] ; |
Incoming search terms:
- cocos2d-x action pause
CCSpawn action in Cocos2d
The CCSpawn action lets you run several actions at the same time. The duration of the CCSpawn action will be the duration of the longest sub-action.
|
1 2 3 4 5 6 |
id action = [CCSpawn actions: [CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4], [CCRotateBy actionWithDuration: 2 angle: 720], nil]; [sprite runAction:action]; |
Speed Actions in Cocos2d
The CCSpeed action modifies the duration of the inner action.
|
1 2 3 4 5 6 7 |
id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCSpeed actionWithAction: move speed:1.0f]; // no speed modification // but you can modify the speed later [action setSpeed: 2.5f]; // speed is 2.5 faster [action setSpeed: 0.5f]; // speed is 0.5 faster (it means 2 times slower) |
difference between @synthesize and @dynamic
@synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)
Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet:
Super class:
|
1 |
@property (nonatomic, retain) NSButton *someButton; ... @synthesize someButton; |
Subclass:
|
1 |
@property (nonatomic, retain) IBOutlet NSButton *someButton; ... @dynamic someButton; |
Incoming search terms:
- distinguish between synthasize & dynamic in ios
CallFuncN and CallFuncND Actions
There are two variations of CCCallFunc. They are CCCallFuncN and CCCallFuncND.
CCCallFuncN takes the node as an argument, and CCCallFuncND takes the node and a pointer to some data.
For example:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
id actionCallFuncN = [CCCallFuncN actionWithTarget:self selector:@selector(doATaskN:)]; // make sure you notice the trailing : id actionCallFuncND = [CCCallFuncND actionWithTarget:self selector:@selector(doATaskND:data:) data:pointerToSomeData]; - (void) doATaskN: (id)node { //some code } - (void) doATaskND: (id)node data:(void*)d { //some code } |



