Tag Archives: Objective-C

How to get Device Orientation in Cocos2D, iPhone in Objective C?

By | April 17, 2012

Hello all…… We may need to know that what is your current device orientation. Using the below code you can do this. Note: If you have to explicitly set the orientation of your phone to any of the above you can set this in the appDelegate.m file. You can put an “||” (OR) symbol in… Read More »

Sprite Animations Without Sprite Sheets

By | April 7, 2012

You can simulate any animations if you have a sequence of images which makes the illusion of that animations and rendering those images to the screen. In cocos2D it can be done in two ways, with sprite sheet animation and without sprite sheets. Here we are going to see how it can be done with… Read More »

Sprite Animations Without Sprite Sheets

By | April 7, 2012

You can simulate any animations if you have a sequence of images which makes the illusion of that animations and rendering those images to the screen. In cocos2D it can be done in two ways, with sprite sheet animation and without sprite sheets. Here we are going to see how it can be done with… Read More »

Sprite Animations Without Sprite Sheets

By | April 7, 2012

You can simulate any animations if you have a sequence of images which makes the illusion of that animations and rendering those images to the screen. In cocos2D it can be done in two ways, with sprite sheet animation and without sprite sheets. Here we are going to see how it can be done with… Read More »

Sprite Animations Without Sprite Sheets

By | April 7, 2012

You can simulate any animations if you have a sequence of images which makes the illusion of that animations and rendering those images to the screen. In cocos2D it can be done in two ways, with sprite sheet animation and without sprite sheets. Here we are going to see how it can be done with… Read More »

Building games for android and iPhone

By | November 27, 2011

Today I will talk about building games for android and iPhone. There are a lot of SDK’s available for building games over the internet and I am here to talk about the CORONA SDK. Corona SDK is a software development kit created by Walter Luh, co-founder of Ansca Mobile. It allows software programmers to build… Read More »

How to detect shake in iPhone ? An example

By | April 13, 2011

Hi, Sometimes you may want to detect shake gesture in iPhone using your programs. But how can you detect shake gesture in iPhone? Shake gesture in iPhone can be detected by using the accelerometer. The following lines of code can be used for detecting the shake gesture in iPhone. You can use these lines of… Read More »

How to remove box2D body from world ?

By | April 10, 2011

Hi, If you are a game developer and you are using box2D for real world simulations, you would probably need a particular body to be removed from the box2D world! But how can you remove box2D body from world ? See the following sample code which does the same. – (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {… Read More »

Email id verification using Objective C

By | March 29, 2011

Hi, In order to verify an email address you have entered is valid or not using Objective C, use the following code. – (BOOL) checkYourMail: (NSString *) myEmail{ NSString *checkMail= @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}”; NSPredicate *matchMail = [NSPredicate predicateWithFormat:@”Matching %@”, checkMail]; return [matchMail evaluateWithObject:myEmail]; } 🙂

How to make a sprite visible and invisible in Cocos2D ?

By | March 27, 2011

Hi, In certain situations you may need to make visible or invisible certain sprites. But how to set a sprite visible and invisible in Cocos2D? See the following Cocos2D code. //Set the sprite’s visible value to 1 to make it visible yourSprite.visible = 1; //Set the sprite’s visible value to 0 to make it invisible… Read More »

How to change the Z value of a Sprite during an action in Cocos2D ?

By | March 27, 2011

Hi, There may arise some situations where you need to change the z value of a particular sprite during an action in Cocos2D. So how can you do that? See the following lines of code. CCSprite *sample= [CCSprite spriteWithFile:@”trialImage.png”]; sample.position = ccp(160,240); [self addChild:sample z:1]; /* Some of your actions goes here! */ [self reorderChild:sample… Read More »

Creating a Button using Objective C

By | March 26, 2011

Hi, Sometimes you may need to create some buttons to the View using Objective C code rather than using Interface Builder. Here is how you can do that easily and efficiently. //You can create button with type. Here I am creating a Custom Button UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; //Then what? Give action to be… Read More »

Splitting a string using symbols in Objective C

By | March 20, 2011

Hi, If you want to split a string between a symbol like, ‘.’ or ‘-‘ or ‘,’ in Objective C, what to do? See the code for how to split string in Objective C. NSString *myString = @”song.mp3”; NSArray *splitArray = [myString componentsSeparatedByString:@”.”]; This code will split the string ‘myString’ into ‘song’ & ‘mp3’ (separated… Read More »

How to stop the sprite sheet animation in cocos2D ?

By | March 17, 2011

Hi, In one of our previous post we have discussed how to animate sprite sheet in cocos2D. In some cases you may need to stop the sprite sheet animation abruptly. How to do that? Here the way to do that. Use the following. [spriteName stopAction:spriteNameAction]; where spriteName is the name of your sprite & spriteNameAction… Read More »