Category Archives: ANDROID

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 »

How to create OptionsMenu in ANDROID?, a simple example……

By | March 16, 2011

This is a simple example of creating options Menu in ANDROID. This menu can be seen by clicking on the “Menu Button” in ANDROID. Check out this example. The main.xml for the above code is

Context menu in android

By | March 16, 2011

What is context menu? Where it is used? How it is used? I will cover all these questions… Context Menu A context menu is conceptually similar to the menu displayed when the user performs a “right-click” on a PC. You should use a context menu to provide the user access to actions that pertain to… Read More »

Crop an Image in ANDROID.

By | March 15, 2011

Cropping an image in ANDROID programmatically has always been a problem for ANDROID developers. So Here I am putting a sample code to demonstrate this. For cropping an image in ANDROID we need a source bitmap which is our image itself, the other one is the target bitmap which we have to set the size… Read More »

Sprite Sheet Animation in Cocos2D – An Example

By | March 14, 2011

Hi, Suppose you have a sprite sheet of the desired animation you want. But how will you use that sprite sheet animation in your program using cocos2D? That’s simple. See the following code first. //Initializing a CCSpriteBatchNode with our sprite sheet image CCSpriteBatchNode *newSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@”jumpingOver.png”]; //Adding the spriteSheet to the layer & setting… Read More »

How to create a new Virtual SD card in emulator in ANDROID? How to start emulator with the created SDCard?

By | March 13, 2011

OK The first question is 1. How to create a new Virtual SD card in emulator in ANDROID? Many times we may have not enough memory for our application to run on the emulator. So what we do? One method is to create new virtual device with more memory. Another method is to extend the… Read More »

How to create a scrolling ListView in android?

By | March 12, 2011

ListView is like a tableView in iPhone or iOS . In this example i will show you how to add a String Array in to the ListView and also make the listView Scrollable. First the xml file . Here the line android:scrollbars=”vertical” will make the scrolling vertically Now the java file The screen will be… Read More »

How to read a folder in the assets directory and read files from it in android?

By | March 12, 2011

File reading is important in android. For the put the files in the assets folder. We can able to read foldername filename Contents of the file First we read the name of the folder. “folder_array” contains all the names of the folder Then if the path is set to Then the list of file name… Read More »

Copying a Sprite Image to another Sprite in Cocos2D

By | March 11, 2011

Hi, Suppose you want to copy a sprite image to another new sprite while using cocos2D. What you do? See the following code… Let oldSprite be your first sprite CCSprite *oldSprite = [CCSprite spriteWithFile:@”ImgOne.png”]; And newSprite be your second sprite CCSprite *newSprite = [CCSprite spriteWithTexture:[oldSprite texture]]; That’s it! Done! Now newSprite too contain ImgOne as… Read More »

Delete a substring in Objective C, Iphone , Mac………….

By | March 10, 2011

This code snippet deletes a substring from a original string.. /** initialize two strings **/ NSString *string = @”This is heaven”; NSString *part = @”heaven”; /** Get the range of the substring in the original string **/ NSRange range = [string rangeOfString:part]; /** Delete the substring from the original string **/ [string deleteCharactersInRange:range]; Please leave… Read More »

Using GridView in ANDROID….

By | March 9, 2011

GridViews are those in which you can arrange elements in a two dimensional grid. It is what you see in the gallery where images are arranged. Here images are arranged in a two dimensional grid. Copy the below code and save it as “MyGridView.java” Now create another file named “Images.java” and copy the below code… Read More »

Android TableLayout

By | March 9, 2011

In android there are different layouts and we often confuse about which one to use. Even if we select one, it is little complicated. So this tutorials is to show you about the TableLayout Here i first created linear Layout in which a Table Layout is added Here you can see that the first row… Read More »

How to make gear joint in Box2D, iPhone?

By | March 7, 2011

Gear joints are one of the real specialities of Box2D. By creating gear joints between two bodies you can actually simulate a real world gear. For creating a gear joint you need two bodies connected by a revolute or prismatic joint. The below code creates two bodies in the shape of a circle which is… Read More »

Read a plist from your resources folder in Iphone Objective C

By | March 6, 2011

Plist or property list are usually used for storing data in iPhone. They are normal XML files, you can open it in a texteditor to view it’s data. This sample code shows how to read data from the plist. Reading a plist will return an array.You can print out the array to view the results.… Read More »

Remove unwanted memory from iPhone….

By | March 5, 2011

Hi all …… You know iPhone doesnot have garbage collection like ANDROID. So it becomes the responsibility of the developer or programmer to release the resources and remove the unwanted textures from your memory. If you don’t remove the unused textures and other variables from your memory your application will exit after a while. You… Read More »

Collision Detection In Box2D – Using With Cocos2D

By | March 5, 2011

For an interactive game building using Box2D, collision detection of Box2D bodies is necessary. There is an easy way to implement collision detection in Box2D. For checking whether two bodies have collided with each other in Box2D while using it with cocos2D, then use the following lines of code where ever you want to check… Read More »

Removing Unused Textures in Cocos2D

By | March 5, 2011

Sometimes unused textures may cause you memory leak! So you need to remove the unused textures. For removing unused textures, use the following line of code, where ever you want to remove unused textures. [[TextureMgr sharedTextureMgr] removeUnusedTextures]; 🙂

Removing Forces From Your World in Box2D Cocos2D

By | March 5, 2011

Hi, In certain situations you may need to remove all the forces you have applied on different bodies in your box2D world. Then what to do? Removing all the forces from the bodies in the box2D world is simple. Just use the single line of code. yourWorld->ClearForces(); Here yourWorld is your Box2D world. Simple, isn’t… Read More »

How to load a URL in Objective C or Cocoa in iPhone?/ Open Safari in Objective C

By | March 1, 2011

This code snippet helps you to open a webpage in Safari. Code uses openURL to load the webpage in the web browser. Write this function as an action to a button……… – ( IBAction ) loadWebPageInSafari : ( id ) sender { NSURL *my_URL = [NSURL URLWithString:[Your_URL stringValue]]; if ( [ [NSWorkspace sharedWorkspace] openURL :… Read More »

How to get a selected Item from a spinner in ANDROID?

By | February 28, 2011

We have come across this issue many times during programming to get a selected item in your combobox. ANDROID has built in functions to get the selected item from a spinner. Take a look at the snippet. Here my_spinner id the spinner variable and using getSelectedItem() which will return an object and by using toString()… Read More »