Archive for 'cocos2d'

How to change sprite’s speed dynamically?

You have to use a CCSpeed action:

CCSpeed* speed= [CCSpeed actionWithAction: yourMoveAction speed: 1.0f];

// yourMoveAction is an action like CCMoveTo for example

[sprite runAction: speed];

Then you can change the speed while the sprite moves with setSpeed:

[speed setSpeed: 2.0f];

Incoming search terms:

  • how to change a sprites speed
  • objective-c sprite speed

Sending mail in Landscape mode : cocos2d

I used several codes to fix this problem. Finally, this just fixed my problem.

in .h file :

#import <MessageUI/MFMailComposeViewController.h>

@interface Game : CCLayer <MFMailComposeViewControllerDelegate>
{

NSString *emailTitle;
NSString *emailBody;
UIImage *emailImage;
MFMailComposeViewController *picker;
}
-(void)showMailPicker;
-(id)initWithTitle:(NSString *)title body:(NSString *)body image:(UIImage *)image;

in .m file :

-(id) init
{
if( (self=[super init])) {

[self showMailPicker];

}
return self;
}

-(id)initWithTitle:(NSString *)title body:(NSString *)body image:(UIImage *)image
{
self = [super init];
if (self != nil) {
emailTitle = title;
emailBody = body;
emailImage = image;
[self showMailPicker];
}
return self;
}

-(void)showMailPicker
{
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.modalPresentationStyle = UIModalPresentationFullScreen;
picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[picker setSubject:emailTitle];
[picker setMessageBody:emailBody isHTML:YES];

[[CCDirector sharedDirector] pause];
UIViewController *rootViewController = (UIViewController *)[[[CCDirector sharedDirector] openGLView ] nextResponder];  // This will do it

[rootViewController presentModalViewController:picker animated:YES];
[picker release];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[CCDirector sharedDirector] resume];
[controller dismissModalViewControllerAnimated: YES];
}

 

Incoming search terms:

  • mail controller in cocos2d
  • mfmailcomposeviewcontroller landscape iphone
  • MFMailComposeViewController landscape iphone dev
  • send email form ios dev cocos2d

How to include and use new fonts in iPhone SDK?

  1. Add the font files to your resource files
  2. Edit your Info.plist: Add a new entry with the key Fonts provided by application.
  3. For each of your files, add the file name to this array

In your application you can the use [UIFont fontWithName:@"YourFontName" size:14.f].

Note: this is available in iOS 3.2 and later.

labelName.backgroundColor = [UIColor clearColor];   // where labelName is the UILabel //

labelName.textAlignment = NSTextAlignmentCenter; // for iOs 6 //

Incoming search terms:

  • make uilabel as background cocos2d

Get current day,month and year

NSDate *now = [NSDate date];

NSLog(@”now: %@”, now); // now: 2011-02-28 09:57:49 +0000

NSString *strDate = [[NSString alloc] initWithFormat:@”%@”,now];
NSArray *arr = [strDate componentsSeparatedByString:@" "];
NSString *str;
str = [arr objectAtIndex:0];
NSLog(@”strdate: %@”,str); // strdate: 2011-02-28

NSArray *arr_my = [str componentsSeparatedByString:@"-"];

NSInteger date = [[arr_my objectAtIndex:2] intValue];
NSInteger month = [[arr_my objectAtIndex:1] intValue];
NSInteger year = [[arr_my objectAtIndex:0] intValue];

NSLog(@”year = %d”, year); // year = 2011
NSLog(@”month = %d”, month); // month = 2
NSLog(@”date = %d”, date); // date = 2

Incoming search terms:

  • cocos2dx how to get current month and day

/* Creating UIVIew and adding ScrollView to it and adding items to that ScrollView*/

// in .h File //
UIView *profileView;
UIScrollView *verticalScroll;

// in .m File //
-(void)show_{
// Create a UI View //
profileView = [[UIView alloc] init];
profileView.frame = CGRectMake(0, 0, 320, 480);
profileView.backgroundColor = [UIColor blueColor];
[[[CCDirector sharedDirector] openGLView] addSubview:profileView];

// Create a UIScroll View //
verticalScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 420)];
verticalScroll.backgroundColor = [UIColor yellowColor];
verticalScroll.showsVerticalScrollIndicator = NO;
verticalScroll.contentSize = CGSizeMake(300, 760);
verticalScroll.center = CGPointMake(160, 250);
verticalScroll.pagingEnabled = FALSE;
[profileView addSubview:verticalScroll];

// Create and add an UIImageView to the ScrollView //
UIImageView *baseImg1 = [[UIImageView alloc] initWithFrame:CGRectMake(5, 20, 325, 65)];
baseImg1.image = [UIImage imageNamed:@"imageName.png"];
baseImg1.center =CGPointMake(150, 340);
[verticalScroll addSubview:baseImg1];
[baseImg1 release];

}

Incoming search terms:

  • add uiimageview to uiscrollview in cocos2d

You can use the following lines of code to make the view looks like a pop up with fade-In effect. For that, first create an UIVIew and assign its alpha value to zero. Here, my UIView is named as : ‘MyView’ :

// Function for FadeIn/PopUp effect for the UIView //

-(void)effectFunction_FadeIn{
MyView.transform = CGAffineTransformMakeScale(1.3, 1.3);
MyView.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
MyView.alpha = 1;
MyView.transform = CGAffineTransformMakeScale(1, 1);
}];
}

 

Now, you can use the below code to make it disappear like a popout/ with Fade-Out effect:

-(void)effectFunction_FadeOut{
MyView.transform = CGAffineTransformMakeScale(1.3, 1.3);
MyView.alpha = 1;
[UIView animateWithDuration:.35 animations:^{
MyView.alpha = 0;
MyView.transform = CGAffineTransformMakeScale(1, 1);
}];
}

 

Incoming search terms:

  • how to add uiview animation in cocos2d

How to install cocos2d v2.0.0 in xcode 4.5

step 1: Find the xcode file templates folder. To find this folder you do the following

-open xcode preferences.

-under preferences select locations.

-there you can see an option named ‘derived data’. Under that you can see a finder path and an arrow.

-click on the arrow. Then you will get  the folder named ‘xcode’ . From this folder find the ‘file template’ folder in which the cocos2d file templates are

stored.(the ‘file templates’ may be in another folder named ‘templates’ which will be in the folder ’xcode’). Delete the all cocos2d template folders. If

there is no cocos2d templates then goto step2.

step2: Open terminal window. Then do exactly as follows.

-type ‘cd ‘(cd+space)

-Unzip the downloaded cocos2d file and then drag and drop this folder into the terminal window.

-press enter key

-type ./install-templates.sh -f

-press enter key.

Now you can see the cocos2d ios template is installing.

Incoming search terms:

  • how to install cocos2d in xcode 4 5
  • how to install cocos2d html5 templates in xcode
  • how to install cocos2d xcode 4 5

Replace a sprite with a new image in Cocos2d

First create sprite (eg : spr_1).

Then for replacing thatsprite, use the following code:

Incoming search terms:

  • cocos2d html5 change frame of sprite

For getting the xib file from the resources, the following line of code is used :

[[NSBundle mainBundle] loadNibNamed:@”myXIBName” owner:self options:nil];

Now in order to get the main view of the XIB, use the following code :

UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@”myXIBName”owner:self options:nil] objectAtIndex:0];

The above code will load the main view that is added in the xib file to the UIView object, myView.

We can add this UIView object to the Cocos2D scene as follows :

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

Incoming search terms:

  • cocos2d x add uiview
  • cocos2dx objective-c uiview
  • how to add uiview with xib into cocos2d
  • how to create a new xib file and object in cocos2d tutorial
Page 1 of 812345...Last »