Sunday, 24 November 2013

How to shuffle an NSMutableArray in an easy way

There are several methods to sort an NSMutableArray. Here we will give you a very simple method to shuffle your NSMutableArray. This method uses the default exchangeObjectAtIndex method to shuffle the array.

Lets initialise a mutable array and add some elements to it as below:

 // Initialising the NSMutableArray
   NSMutableArray *myArray = [[NSMutableArray alloc]init];

 // Add some objects to it (say 15, here) 
   for (int i=1; i<=15; i++) {
     [myArray addObject:[NSString stringWithFormat:@"%d",i]];
   }

Now you have an array with 15 objects/elements in it. Now for sorting the above array, you just need to use the following code:

 // Code for shuffling
  for (int i = 0; i < [myArray count]; ++i) {
    [myArray exchangeObjectAtIndex:i withObjectAtIndex:((random() % ([myArray count]-i)) + i)];
  }


Wednesday, 20 November 2013

How to set the master volume and individual channel volume in corona SDK




This tutorial will help you to change/adjust the volume of the music playing in your corona SDK application.

  • To set the master volume, you can simply call the following line:

  audio.setVolume( 0.5 )

This will setup the master volume to half. The value range from 0.0 (min.) to 1.0 (max.).


  • And, if you need to set the volume of an individual music channel, then you can use the following:
  audio.setVolume( 0.75, { channel=1 } ) 
This will control the volume of channel 1 (here, it will make the channel 1 volume to 3/4th of the default/full volume).

How to play background music in corona SDK application

This is a simple tutorial, which will teach you how to play background music in your corona SDK applications. 

First, load the music as:
  local backgroundMusic = audio.loadStream("bgMusic.mp3") 

Then you can play the music in loop as:

  local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1,
                                                                                                              loop    s=-1,   
                                                                                                              fadein   =5000 })


where, channel is an integer value representing the music channel (0-32)

And if you want to stop the music, you can use:
  audio.stop( backgroundMusicChannel )

Tuesday, 5 November 2013

How to Install cocos2d in Xcode

Cocos2d is a powerful game engine, that can be added inside Xcode. It's installation steps are as simple as below:


  • Keep the downloaded file in your desktop.
  • Open terminal and type cd
  • Drag your latest version of cocos2d package into the terminal window.
  • Type sudo and open the cocos2d package, and drag the 'install-templates.sh' file into your terminal window. Then press 'Enter'.
  • Put your administrator password to install templates.
Now open your Xcode and see that the cocos2d has been successfully integrated. That's all...


How to hide status bar in iOS7

This post is about the UIStatusBar issue with the iOS 7, Xcode based applications. In your latest application, you can hide the UIStatusBar on application launch by selecting the Hide during application launch property as below:





But this isn't enough for hiding the ststusbar inside the app. That is, inside your iOS 7 app, you may see the status bar as it is:



For solving this, just do the following:
  • Open your info.plist
  • Add a row and name it as : View controller-based status bar appearance and set it to NO


That is: 

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

We also attaching sample screenshot for your information: