Showing posts with label device. Show all posts
Showing posts with label device. Show all posts

Monday, 28 October 2013

How to check whether the testing device supports vibration facility in corona SDK

You may need to implement vibration feedbacks in many of your applications, especially in games and during warning alerts. In this chapter, you will learn about the a boolean key event to check whether your device supports vibrational feedback for your corona app. If this key event returns true,then your device will support vibration feedbacks, and if it returns false, then your device won't.



--  Function to trigger key event --
local function onKeyEvent( event )
    -- Vibrate the gamepad if its 'A' button was pressed.
    if (event.keyName == "button_A") and (event.phase == "down") then
        if event.device and event.device.canVibrate then
            event.device:vibrate()
        end
    end
end

Runtime:addEventListener( "key", onKeyEvent )



Note: This will not work with Android versions <= 4.0.

Friday, 23 August 2013

Different device Orientation in Corona SDK

In this tutorial, we will teach you: how to setup different supported orientations
for your Corona SDK application. These tricks are done in the build.settings file.
It will setup app orientation in relation to the device's physical orientation.
This also includes auto orientation triggered by the accelerometer, if the
device is flipped/rotated during runtime.

By this, you can set the orientation for:
    1) Launch image(splash screen).
    2) Native UI elements(like alerts, native keyboard,etc).
    3) The Corona display stage.
   
We will show you some of the examples in different orientations.

Example 1: Only landscapeLeft
 

    settings =
        {
            orientation =
            {
                default = "landscapeRight",
            },
        }



 
Example 2: Both landscapeLeft and landscapeRight


    settings =
    {
        orientation =
        {
            default = "landscapeRight",
            supported = { "landscapeLeft", "landscapeRight" },
        },
    }


   
Example 3: Only portrait    
 


    settings =
        {
            orientation =
            {
                default = "portrait",
            },
        }




Example 4: Both portrait and portraitUpsideDown


    settings =
    {
        orientation =
        {
            default = "portrait",
            supported = { "portrait", "portraitUpsideDown" },
        },
    }




Tuesday, 4 June 2013

How to check whether there is internet connection with the device: cocos2d/Xcode

You can check whether there is internet connection with the device/not with the help of following code:

     // in .h File //

        Import Reachability class.
       


    // in .m File //

        if([self connected] )
        {
            NSLog(@"Internet connected\n");
        }
       
        - (BOOL)connected
        {
            Reachability *reachability = [Reachability reachabilityForInternetConnection];
            NetworkStatus networkStatus = [reachability currentReachabilityStatus];
            return !(networkStatus == NotReachable);
        }

Monday, 3 June 2013

How to programmatically change the device orientation instantly: cocos2d

To change Device orientation instantly, use the following syntax:

Syntax:

    CCDirector *director = [CCDirector sharedDirector];
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];  // set your desired orientation here

Sunday, 2 June 2013

How to get device orientation programmatically: cocos2d

Tho get the device orientation programmatically, you can use the following code:


    if([[UIDevice currentDevice] orientation] == kCCDeviceOrientationPortrait) {
        NSLog(@"Portrait");
    }
    else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeLeft) {
        NSLog(@"LandscapeLeft");
    }
    else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeRight) {
        NSLog(@"LandscapeRight");
    }
    else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationPortraitUpsideDown) {
        NSLog(@"PortraitUpsideDown");
    }