Showing posts with label load. Show all posts
Showing posts with label load. Show all posts

Wednesday, 20 November 2013

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, 30 July 2013

How to load a remote image to your application screen using Corona SDK

 Is it possible to load a picture that is located on a server, and display it on your application screen using corona SDK..? Yes it is...
You can use the following code for achieving this:

local function networkListener( event )
        if ( event.isError ) then
                print ( "Network error - download failed" )
        else
                event.target.alpha = 0
                transition.to( event.target, { alpha = 1.0 } )
        end

        print ( "RESPONSE: " .. event.response )
end

display.loadRemoteImage( "http://goo.gl/FsRnwu", "GET", networkListener, "banner.png", system.TemporaryDirectory, 25, 50 )

Sunday, 2 June 2013

How to read an image from file and display it in an UIImageView programmatically: cocos2d/Xcode

Reading an image from  file and displaying it on an ImageView is very siple as follows:

    -(void)CreateView{

        // Fetch saved image //

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *imgPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Img_%d.png",currentProfileIndex]];
            UIImage *img_1 = [UIImage imageWithContentsOfFile:imgPath];

      
        // Create an UIView //
       
            UIView *bgView = [[UIView alloc] init];
            bgView.frame = CGRectMake(240, 160, 10, 10);
            bgView.backgroundColor = [UIColor clearColor];
            [[[CCDirector sharedDirector]openGLView] addSubview:bgView];   


       // Create an UIImageView and display to display the image //

            UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(240, 160, 50, 50)];
            bgImg.image = img_1;                    // Set the saved image to the UIImageView
            bgImg.center = CGPointMake(100, 100);
            [bgView addSubview:bgImg];
        }