Play with shaders – black and white – part 1

While developing my game ‘Ice Heroes’, i discovered the shaders with cocos2d. I won’t explain in detail what is it, there is tons of resources about it, but basically, it is a small program used to display an object (http://www.opengl.org/wiki/Shader). If you have a look at the cocos2d sources, you can see that every node rendered on screen is using a default shader: kCCShader_PositionTextureColor. This program key is set in CCShaderCache.m in loadDefaultShaders. It is composed of a vertex shader (executed on every vertex), and a fragment shader (executed every pixel on...

read more

Twitter post with cocos2d 2.x

Here is what i am using for tweets: You need the twitter.framework and #import <Twitter/Twitter.h> -(void) postTweet { AppController * app = (((AppController*) [UIApplication sharedApplication].delegate)); TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init]; [tweetViewController setInitialText:@"blablabalbalblabla"]; [tweetViewController setCompletionHandler: ^(TWTweetComposeViewControllerResult result) { dispatch_async(dispatch_get_main_queue(), ^{ { if (result == TWTweetComposeViewControllerResultDone) { //success } else if(result ==...

read more

Instagram and cocos2d 2.x

A quick method to send a photo to instagram -(void)postInstagram { AppController *app = (AppController*) [[UIApplication sharedApplication] delegate]; UIImage * screenshot = [self takeScreenShot]; NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Screenshot.igo"]; // Write image to jpeg [UIImageJPEGRepresentation(screenshot, 1.0) writeToFile:savePath atomically:YES]; NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { UIDocumentInteractionController *documentInteractionController =...

read more

Posting on facebook with cocos2d

This is another quick tutorial, showing how to post / email what you need. We will use the social.framework (don’t forget to add it to your library list, or you won’t be able to use the SLComposeViewController. I was using ShareKit (i should say trying to use) for all my needs (facebook, emails, tweeter, instagram etc….), the install setup is imho too heavy and time consuming. I also had several strange bugs like window not appearing every time (first button tap: no window, second: FB window appeared, then never appear….). Posting is usually some lines of code, i...

read more

How to send an email with cocos2d

We will use MFMailComposeViewController, and we want to send a email with preformated subject and body, and an image as attachment: First, add the MFMailComposeViewControllerDelegate to your .h, this delegate method will be called when you have finish using the controller (after cancelling or sending the email): -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error Here is the code, basically we pause the cocos2d animation, prepare the controller with the subject/body and a screenshot file which is...

read more