code:
// Setup program for the Cocos2d-win32 App Wizard for VC++ 9.0 (Orcas)

main();

function EchoInfo(bQuiet, strMsg) {
    if (! bQuiet) {
        WScript.Echo(strMsg);
    }
    else {
        var FileSys = new ActiveXObject("Scripting.FileSystemObject");
        var strLogPath = "InstallWizardLog.txt"
        var file = FileSys.OpenTextFile(strLogPath, 8, true);
        file.WriteLine(strMsg);
        file.Close();
    }
}

function EchoError(bQuiet, strMsg) {
    strMsg = "Error: " + strMsg;
    if (! bQuiet) {
        WScript.Echo(strMsg);
    }
    else {
        var FileSys = new ActiveXObject("Scripting.FileSystemObject");
        var strLogPath = "InstallWizardLog.txt"
        var file = FileSys.OpenTextFile(strLogPath, 8, true);
        file.WriteLine(strMsg);
        file.Close();
    }
}

function main() {
    // Decode command line arguments
    var bDebug = false;
    var bQuiet = false;
    var bElevated = false;
    var Args = WScript.Arguments;
    for (var i = 0; i < Args.length; i++) {
        if (Args(i) == "/debug")
            bDebug = true;
        else if (Args(i) == "/elevated")
            bElevated = true;
        else if (Args(i) == "/quiet")
            bQuiet = true;
    }

    // See if UAC is enabled
    var Shell = WScript.CreateObject("Shell.Application");
    if (!bElevated && Shell.IsRestricted("System", "EnableLUA")) {
        // Check that the script is being run interactively.
        if (!WScript.Interactive) {
            EchoError(bQuiet, "(Windows LUA) Elevation required.");
            return;
        }

        // Now relaunch the script, using the "RunAs" verb to elevate
        var strParams = "\"" + WScript.ScriptFullName + "\"";
        if (bDebug)
            strParams += " /debug";
        strParams += " /elevated";
        Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");
        return;
    }

    // Create shell object
    var WSShell = WScript.CreateObject("WScript.Shell");
    // Create file system object
    var FileSys = WScript.CreateObject("Scripting.FileSystemObject");

    // Get the folder containing the script file
    var strScriptPath = FileSys.GetParentFolderName(WScript.ScriptFullName);
    if (strScriptPath == null || strScriptPath == "")
        strScriptPath = ".";

    // Get the folder script files copy to
    var strValue = "";
    try {
        var strVC9Key = "HKLM\\Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
        strValue = WSShell.RegRead(strVC9Key);
    }
    catch (e) {
        try {
            var strVC9Key_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
            strValue = WSShell.RegRead(strVC9Key_x64);
        }
        catch (e) {
            EchoError(bQuiet, "Cannot find where Visual Studio 2008 is installed.");
            return;
        }
    }

    var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");
    if (bDebug)
        WScript.Echo("Destination: " + strDestFolder);

    if (!FileSys.FolderExists(strDestFolder)) {
        EchoError(bQuiet, "Cannot find destination folder (should be: " + strDestFolder + ")");
        return;
    }

    // Wizard Info
    var nNumWizards = 2;

    var astrWizardName = new Array();
    astrWizardName[0] = "CCAppWiz.win32";
    astrWizardName[1] = "CCAppWiz.wophone";

    var nCntr;
    for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
        var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);

        if (bDebug)
            WScript.Echo("Source: " + strSourceFolder);

        if (!FileSys.FolderExists(strSourceFolder)) {
            EchoError(bQuiet, "Cannot find Wizard folder (should be: " + strSourceFolder + ")");
            return;
        }

        // Copy files
        try {
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".ico");
            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".ico");
            FileSys.CopyFile(strSrc, strDest);

            strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
            strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsdir");
            FileSys.CopyFile(strSrc, strDest);
        }
        catch (e) {
            var strError = "no info";
            if (e.description.length != 0)
                strError = e.description;
            EchoError(bQuiet, "Cannot copy file (" + strError + ")");
            return;
        }

        // Read and write CCAppWiz.vsz, add engine version and replace path when found
        try {
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsz");
            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsz");

            var ForReading = 1;
            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
            if (fileSrc == null) {
                EchoError(bQuiet, "Cannot open source file: " + strSrc);
                return;
            }

            var ForWriting = 2;
            var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
            if (fileDest == null) {
                EchoError(bQuiet, " Cannot open destination file: " + strDest);
                return;
            }

            while (!fileSrc.AtEndOfStream) {
                var strLine = fileSrc.ReadLine();
                if (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
                    strLine += ".9.0";
                else if (strLine.indexOf("WIZARD_VERSION") != -1)
                    strLine = "Param=\"WIZARD_VERSION = 9.0\"";
                else if (strLine.indexOf("ABSOLUTE_PATH") != -1)
                    strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
                fileDest.WriteLine(strLine);
            }

            fileSrc.Close();
            fileDest.Close();
        }
        catch (e) {
            var strError = "no info";
            if (e.description.length != 0)
                strError = e.description;
            EchoError(bQuiet, "Cannot read and write CCAppWiz.vsz (" + strError + ")");
            return;
        }
    }

    // Create Cocos2d-x folder
    var strDestCCFolder = "";
    try {
        strDestCCFolder = FileSys.BuildPath(strDestFolder, "Cocos2d-x");
        if (!FileSys.FolderExists(strDestCCFolder))
            FileSys.CreateFolder(strDestCCFolder);
        if (bDebug)
            WScript.Echo("Cocos2d-x Folder: " + strDestCCFolder);
    }
    catch (e) {
        var strError = "no info";
        if (e.description.length != 0)
            strError = e.description;
        EchoError(bQuiet, "Cannot create Cocos2d-x folder (" + strError + ")");
        return;
    }

    // Read and write additional CCAppWiz.vsdir and CCAppWiz.uphone.vsdir, add path to the wizard location
    try {
        var strDest = FileSys.BuildPath(strDestCCFolder, "Cocos2d-x.vsdir");

        var ForWriting = 2;

        var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
        if (fileDest == null) {
            EchoError(bQuiet, "Cannot open destination file: " + strDest);
            return;
        }

        var nCntr;
        for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
            var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
            var ForReading = 1;
            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
            if (fileSrc == null) {
                EchoError(bQuiet, "Cannot open source file: " + strSrc);
                return;
            }

            while (!fileSrc.AtEndOfStream) {
                var strLine = fileSrc.ReadLine();
                if (strLine.indexOf(astrWizardName[nCntr] + ".vsz|") != -1)
                    strLine = "..\\" + strLine;
                fileDest.WriteLine(strLine);
            }

            fileSrc.Close();
        }
        fileDest.Close();
    }
    catch (e) {
        var strError = "no info";
        if (e.description.length != 0)
            strError = e.description;
        EchoError(bQuiet, "Cannot read and write Cocos2d-x\\CCAppWiz.vsdir (" + strError + ")");
        return;
    }

    EchoInfo(bQuiet, "App Wizard successfully installed for VS2008!");
}


code:
// Setup program for the Cocos2d-win32 App Wizard for VC++ 10.0 (VC2010)

main();

function EchoInfo(bQuiet, strMsg) {
    if (! bQuiet) {
        WScript.Echo(strMsg);
    }
    else {
        var FileSys = new ActiveXObject("Scripting.FileSystemObject");
        var strLogPath = "InstallWizardLog.txt"
        var file = FileSys.OpenTextFile(strLogPath, 8, true);
        file.WriteLine(strMsg);
        file.Close();
    }
}

function EchoError(bQuiet, strMsg) {
    strMsg = "Error: " + strMsg;
    if (! bQuiet) {
        WScript.Echo(strMsg);
    }
    else {
        var FileSys = new ActiveXObject("Scripting.FileSystemObject");
        var strLogPath = "InstallWizardLog.txt"
        var file = FileSys.OpenTextFile(strLogPath, 8, true);
        file.WriteLine(strMsg);
        file.Close();
    }
}

function main() {
    // Decode command line arguments
    var bDebug = false;
    var bQuiet = false;
    var bElevated = false;
    var Args = WScript.Arguments;
    for (var i = 0; i < Args.length; i++) {
        if (Args(i) == "/debug")
            bDebug = true;
        else if (Args(i) == "/elevated")
            bElevated = true;
        else if (Args(i) == "/quiet")
            bQuiet = true;
    }

    // See if UAC is enabled
    var Shell = WScript.CreateObject("Shell.Application");
    if (!bElevated && Shell.IsRestricted("System", "EnableLUA")) {
        // Check that the script is being run interactively.
        if (!WScript.Interactive) {
            EchoError(bQuiet, "(Windows LUA) Elevation required.");
            return;
        }

        // Now relaunch the script, using the "RunAs" verb to elevate
        var strParams = "\"" + WScript.ScriptFullName + "\"";
        if (bDebug)
            strParams += " /debug";
        strParams += " /elevated";
        Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");
        return;
    }

    // Create shell object
    var WSShell = WScript.CreateObject("WScript.Shell");
    // Create file system object
    var FileSys = WScript.CreateObject("Scripting.FileSystemObject");

    // Get the folder containing the script file
    var strScriptPath = FileSys.GetParentFolderName(WScript.ScriptFullName);
    if (strScriptPath == null || strScriptPath == "")
        strScriptPath = ".";

    // Get the folder script files copy to
    var strValue = "";
    try {
        var strVCKey = "HKLM\\Software\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir";
        strValue = WSShell.RegRead(strVCKey);
    }
    catch (e) {
        try {
            var strVCKey_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir";
            strValue = WSShell.RegRead(strVCKey_x64);
        }
        catch (e) {
            EchoError(bQuiet, "Cannot find where Visual Studio 2010 is installed.");
            return;
        }
    }

    var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");
    if (bDebug)
        WScript.Echo("Destination: " + strDestFolder);

    if (!FileSys.FolderExists(strDestFolder)) {
        EchoError(bQuiet, "Cannot find destination folder (should be: " + strDestFolder + ")");
        return;
    }

    // Wizard Info
    var nNumWizards = 2;

    var astrWizardName = new Array();
    astrWizardName[0] = "CCAppWiz.win32";
    astrWizardName[1] = "CCAppWiz.wophone";

    var nCntr;
    for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
        var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);

        if (bDebug)
            WScript.Echo("Source: " + strSourceFolder);

        if (!FileSys.FolderExists(strSourceFolder)) {
            EchoError(bQuiet, "Cannot find Wizard folder (should be: " + strSourceFolder + ")");
            return;
        }

        // Copy files
        try {
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".ico");
            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".ico");
            FileSys.CopyFile(strSrc, strDest);

            strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
            strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsdir");
            FileSys.CopyFile(strSrc, strDest);
        }
        catch (e) {
            var strError = "no info";
            if (e.description.length != 0)
                strError = e.description;
            EchoError(bQuiet, "Cannot copy file (" + strError + ")");
            return;
        }

        // Read and write CCAppWiz.vsz, add engine version and replace path when found
        try {
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsz");
            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsz");

            var ForReading = 1;
            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
            if (fileSrc == null) {
                EchoError(bQuiet, "Cannot open source file: " + strSrc);
                return;
            }

            var ForWriting = 2;
            var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
            if (fileDest == null) {
                EchoError(bQuiet, " Cannot open destination file: " + strDest);
                return;
            }

            while (!fileSrc.AtEndOfStream) {
                var strLine = fileSrc.ReadLine();
                if (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
                    strLine += ".10.0";
                else if (strLine.indexOf("WIZARD_VERSION") != -1)
                    strLine = "Param=\"WIZARD_VERSION = 10.0\"";
                else if (strLine.indexOf("ABSOLUTE_PATH") != -1)
                    strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
                fileDest.WriteLine(strLine);
            }

            fileSrc.Close();
            fileDest.Close();
        }
        catch (e) {
            var strError = "no info";
            if (e.description.length != 0)
                strError = e.description;
            EchoError(bQuiet, "Cannot read and write CCAppWiz.vsz (" + strError + ")");
            return;
        }
    }

    // Create Cocos2d-x folder
    var strDestCCFolder = "";
    try {
        strDestCCFolder = FileSys.BuildPath(strDestFolder, "Cocos2d-x");
        if (!FileSys.FolderExists(strDestCCFolder))
            FileSys.CreateFolder(strDestCCFolder);
        if (bDebug)
            WScript.Echo("Cocos2d-x Folder: " + strDestCCFolder);
    }
    catch (e) {
        var strError = "no info";
        if (e.description.length != 0)
            strError = e.description;
        EchoError(bQuiet, "Cannot create Cocos2d-x folder (" + strError + ")");
        return;
    }

    // Read and write additional CCAppWiz.vsdir and CCAppWiz.uphone.vsdir, add path to the wizard location
    try {
        var strDest = FileSys.BuildPath(strDestCCFolder, "Cocos2d-x.vsdir");

        var ForWriting = 2;

        var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
        if (fileDest == null) {
            EchoError(bQuiet, "Cannot open destination file: " + strDest);
            return;
        }

        var nCntr;
        for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
            var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);
            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
            var ForReading = 1;
            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
            if (fileSrc == null) {
                EchoError(bQuiet, "Cannot open source file: " + strSrc);
                return;
            }

            while (!fileSrc.AtEndOfStream) {
                var strLine = fileSrc.ReadLine();
                if (strLine.indexOf(astrWizardName[nCntr] + ".vsz|") != -1)
                    strLine = "..\\" + strLine;
                fileDest.WriteLine(strLine);
            }

            fileSrc.Close();
        }
        fileDest.Close();
    }
    catch (e) {
        var strError = "no info";
        if (e.description.length != 0)
            strError = e.description;
        EchoError(bQuiet, "Cannot read and write Cocos2d-x\\CCAppWiz.vsdir (" + strError + ")");
        return;
    }

    EchoInfo(bQuiet, "App Wizard successfully installed for VS2010!");
}

license: mit


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Identifier</key>
	<string>org.cocos2d-x.base</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Options</key>
	<array>
		<dict>
			<key>Description</key>
			<string>Your new product's name.</string>
			<key>EmptyReplacement</key>
			<string>ProductName</string>
			<key>Identifier</key>
			<string>productName</string>
			<key>Name</key>
			<string>Product Name</string>
			<key>NotPersisted</key>
			<true/>
			<key>Required</key>
			<true/>
			<key>Type</key>
			<string>text</string>
		</dict>
		<dict>
			<key>Default</key>
			<string>___VARIABLE_bundleIdentifierPrefix:bundleIdentifier___.___VARIABLE_productName:RFC1034Identifier___</string>
			<key>Description</key>
			<string>Your new product's bundle identifier.</string>
			<key>Identifier</key>
			<string>bundleIdentifier</string>
			<key>Name</key>
			<string>Bundle Identifier</string>
			<key>Type</key>
			<string>static</string>
		</dict>
	</array>
	<key>Project</key>
	<dict>
		<key>Configurations</key>
		<dict>
			<key>Debug</key>
			<dict>
				<key>GCC_OPTIMIZATION_LEVEL</key>
				<string>0</string>
				<key>GCC_PREPROCESSOR_DEFINITIONS</key>
				<array>
					<string>DEBUG</string>
					<string>COCOS2D_DEBUG=1</string>
					<string>USE_FILE32API</string>
					<string>TARGET_OS_IPHONE</string>
				</array>
				<key>GCC_SYMBOLS_PRIVATE_EXTERN</key>
				<string>NO</string>
			</dict>
			<key>Release</key>
			<dict>
				<key>GCC_PREPROCESSOR_DEFINITIONS</key>
				<array>
					<string>NDEBUG</string>
					<string>USE_FILE32API</string>
					<string>TARGET_OS_IPHONE</string>
				</array>
			</dict>
		</dict>
		<key>SharedSettings</key>
		<dict>
			<key>GCC_C_LANGUAGE_STANDARD</key>
			<string>gnu99</string>
			<key>GCC_WARN_ABOUT_RETURN_TYPE</key>
			<string>YES</string>
			<key>GCC_WARN_UNUSED_VARIABLE</key>
			<string>YES</string>
            <key>HEADER_SEARCH_PATHS</key>
            <array>
            <string>"$(PROJECT_NAME)/libs/cocos2dx"</string>
            <string>"$(PROJECT_NAME)/libs/CocosDenshion/include"</string>
            <string>"$(SDKROOT)/usr/include/libxml2"</string>
            </array>
		</dict>
	</dict>
	<key>Targets</key>
	<array>
		<dict>
			<key>BuildPhases</key>
			<array>
				<dict>
					<key>Class</key>
					<string>Sources</string>
				</dict>
				<dict>
					<key>Class</key>
					<string>Frameworks</string>
				</dict>
				<dict>
					<key>Class</key>
					<string>Resources</string>
				</dict>
			</array>
			<key>Configurations</key>
			<dict>
				<key>Debug</key>
				<dict>
					<key>COPY_PHASE_STRIP</key>
					<string>NO</string>
					<key>GCC_DYNAMIC_NO_PIC</key>
					<string>NO</string>
				</dict>
				<key>Release</key>
				<dict>
					<key>COPY_PHASE_STRIP</key>
					<string>YES</string>
				</dict>
			</dict>
			<key>Name</key>
			<string>___PACKAGENAME___</string>
			<key>ProductType</key>
			<string>com.apple.product-type.application</string>
			<key>SharedSettings</key>
			<dict>
				<key>ALWAYS_SEARCH_USER_PATHS</key>
				<string>NO</string>
				<key>PRODUCT_NAME</key>
				<string>$(TARGET_NAME)</string>
				<key>WRAPPER_EXTENSION</key>
				<string>app</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleDisplayName</key>
	<string>${PRODUCT_NAME}</string>
	<key>CFBundleExecutable</key>
	<string>${EXECUTABLE_NAME}</string>
	<key>CFBundleIconFile</key>
	<string></string>
	<key>CFBundleIconFiles</key>
	<array>
		<string>Icon.png</string>
		<string>Icon@2x.png</string>
		<string>Icon-72.png</string>
		<string>Icon-Small-50.png</string>
		<string>Icon-Small.png</string>
		<string>Icon-Small@2x.png</string>
	</array>
	<key>CFBundleIdentifier</key>
	<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>${PRODUCT_NAME}</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1.0</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIPrerenderedIcon</key>
	<true/>
	<key>UIStatusBarHidden</key>
	<true/>
	<key>UIRequiredDeviceCapabilities</key>
	<dict>
		<key>accelerometer</key>
		<true/>
		<key>opengles-1</key>
		<true/>
	</dict>
</dict>
</plist>


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Definitions</key>
	<dict>
		<key>Resources/CloseNormal.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/CloseNormal.png</string>
		</dict>
		<key>Resources/CloseSelected.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/CloseSelected.png</string>
		</dict>
		<key>Resources/Default.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Default.png</string>
		</dict>
		<key>Resources/HelloWorld.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/HelloWorld.png</string>
		</dict>
		<key>Resources/Icon-72.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon-72.png</string>
		</dict>
		<key>Resources/Icon-Small-50.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon-Small-50.png</string>
		</dict>
		<key>Resources/Icon-Small.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon-Small.png</string>
		</dict>
		<key>Resources/Icon-Small@2x.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon-Small@2x.png</string>
		</dict>
		<key>Resources/Icon.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon.png</string>
		</dict>
		<key>Resources/Icon@2x.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Icon@2x.png</string>
		</dict>
		<key>Resources/Info.plist</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/Info.plist</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Resources/iTunesArtwork</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/iTunesArtwork</string>
		</dict>
	</dict>
	<key>Identifier</key>
	<string>org.cocos2d-x.iosbase</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Nodes</key>
	<array>
		<string>Resources/CloseNormal.png</string>
		<string>Resources/CloseSelected.png</string>
		<string>Resources/Default.png</string>
		<string>Resources/HelloWorld.png</string>
		<string>Resources/Icon-72.png</string>
		<string>Resources/Icon-Small-50.png</string>
		<string>Resources/Icon-Small.png</string>
		<string>Resources/Icon-Small@2x.png</string>
		<string>Resources/Icon.png</string>
		<string>Resources/Icon@2x.png</string>
		<string>Resources/Info.plist</string>
		<string>Resources/iTunesArtwork</string>
	</array>
	<key>Platforms</key>
	<array>
		<string>com.apple.platform.iphoneos</string>
	</array>
	<key>Project</key>
	<dict>
		<key>Configurations</key>
		<dict>
			<key>Release</key>
			<dict>
				<key>OTHER_CFLAGS</key>
				<string>-DNS_BLOCK_ASSERTIONS=1</string>
			</dict>
		</dict>
		<key>SDK</key>
		<string>iphoneos</string>
		<key>SharedSettings</key>
		<dict>
			<key>ARCHS</key>
			<string>$(ARCHS_STANDARD_32_BIT)</string>
			<key>CODE_SIGN_IDENTITY[sdk=iphoneos*]</key>
			<string>iPhone Developer</string>
			<key>IPHONEOS_DEPLOYMENT_TARGET</key>
			<string>latest_iphoneos</string>
		</dict>
	</dict>
	<key>Targets</key>
	<array>
		<dict>
			<key>Configurations</key>
			<dict>
				<key>Release</key>
				<dict>
					<key>VALIDATE_PRODUCT</key>
					<string>YES</string>
				</dict>
			</dict>
			<key>Frameworks</key>
			<array>
				<string>QuartzCore</string>
				<string>OpenGLES</string>
				<string>OpenAL</string>
				<string>AudioToolbox</string>
				<string>AVFoundation</string>
				<string>UIKit</string>
				<string>Foundation</string>
				<string>CoreGraphics</string>
			</array>
			<key>SharedSettings</key>
			<dict>
				<key>GCC_THUMB_SUPPORT[arch=armv6]</key>
				<string></string>
				<key>OTHER_LDFLAGS</key>
				<string>-lxml2 -lz</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ancestors</key>
	<array>
		<string>org.cocos2d-x.base</string>
	</array>
	<key>Identifier</key>
	<string>org.cocos2d-x.bundlebase</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Options</key>
	<array>
		<dict>
			<key>Description</key>
			<string>Your company's bundle identifier prefix.</string>
			<key>EmptyReplacement</key>
			<string>com.yourcompany</string>
			<key>Identifier</key>
			<string>bundleIdentifierPrefix</string>
			<key>Name</key>
			<string>Company Identifier</string>
			<key>Required</key>
			<true/>
			<key>Type</key>
			<string>text</string>
		</dict>
		<dict>
			<key>Default</key>
			<string>___VARIABLE_bundleIdentifierPrefix:bundleIdentifier___.___VARIABLE_productName:RFC1034Identifier___</string>
			<key>Description</key>
			<string>Your new product's bundle identifier.</string>
			<key>Identifier</key>
			<string>bundleIdentifier</string>
			<key>Name</key>
			<string>Bundle Identifier</string>
			<key>Type</key>
			<string>static</string>
		</dict>
	</array>
	<key>Targets</key>
	<array>
		<dict>
			<key>SharedSettings</key>
			<dict>
				<key>GCC_PRECOMPILE_PREFIX_HEADER</key>
				<string>YES</string>
				<key>GCC_PREFIX_HEADER</key>
				<string>___PACKAGENAME___/Prefix.pch</string>
				<key>INFOPLIST_FILE</key>
				<string>___PACKAGENAME___/Resources/Info.plist</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#include "AppDelegate.h"

#include "cocos2d.h"
#include "HelloWorldScene.h"

USING_NS_CC;

AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::initInstance()
{
    bool bRet = false;
    do
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView * pMainWnd = new CCEGLView();
        CC_BREAK_IF(! pMainWnd
            || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));

#endif  // CC_PLATFORM_WIN32

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        // OpenGLView is initialized in AppDelegate.mm on ios platform, nothing need to do here.
#endif  // CC_PLATFORM_IOS

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        // OpenGLView is initialized in HelloWorld/android/jni/helloworld/main.cpp
		// the default setting is to create a fullscreen view
		// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif  // CC_PLATFORM_ANDROID

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView* pMainWnd = new CCEGLView(this);
        CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));

#ifndef _TRANZDA_VM_
        // on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
        cocos2d::CCFileUtils::setResource("HelloWorld.zip");
#endif

#endif  // CC_PLATFORM_WOPHONE

#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
		// MaxAksenov said it's NOT a very elegant solution. I agree, haha
		CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif

        bRet = true;
    } while (0);
    return bRet;
}

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    // pDirector->enableRetinaDisplay(true);

	// sets landscape mode
	// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);

	// turn on display FPS
	pDirector->setDisplayFPS(true);

	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);

	// create a scene. it's an autorelease object
	CCScene *pScene = HelloWorld::scene();

	// run
	pDirector->runWithScene(pScene);

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

	// if you use SimpleAudioEngine, it must be pause
	// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();

	// if you use SimpleAudioEngine, it must resume here
	// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "CCApplication.h"

/**
@brief	The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class  AppDelegate : private cocos2d::CCApplication
{
public:
	AppDelegate();
	virtual ~AppDelegate();

    /**
    @brief	Implement for initialize OpenGL instance, set source path, etc...
    */
    virtual bool initInstance();

    /**
    @brief	Implement CCDirector and CCScene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();

    /**
    @brief  The function be called when the application enter background
    @param  the pointer of the application
    */
    virtual void applicationDidEnterBackground();

    /**
    @brief  The function be called when the application enter foreground
    @param  the pointer of the application
    */
    virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_


code:
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"

using namespace cocos2d;
using namespace CocosDenshion;

CCScene* HelloWorld::scene()
{
	// 'scene' is an autorelease object
	CCScene *scene = CCScene::node();

	// 'layer' is an autorelease object
	HelloWorld *layer = HelloWorld::node();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}

	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
										"CloseNormal.png",
										"CloseSelected.png",
										this,
										menu_selector(HelloWorld::menuCloseCallback) );
	pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

	// create menu, it's an autorelease object
	CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
	pMenu->setPosition( CCPointZero );
	this->addChild(pMenu, 1);

	/////////////////////////////
	// 3. add your codes below...

	// add a label shows "Hello World"
	// create and initialize a label
	CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34);

	// ask director the window size
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	// position the label on the center of the screen
	pLabel->setPosition( ccp(size.width / 2, size.height - 20) );

	// add the label as a child to this layer
	this->addChild(pLabel, 1);

	// add "HelloWorld" splash screen"
	CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");

	// position the sprite on the center of the screen
	pSprite->setPosition( ccp(size.width/2, size.height/2) );

	// add the sprite as a child to this layer
	this->addChild(pSprite, 0);

	return true;
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
	CCDirector::sharedDirector()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	exit(0);
#endif
}


code:
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::CCLayer
{
public:
	// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
	virtual bool init();

	// there's no 'id' in cpp, so we recommand to return the exactly class pointer
	static cocos2d::CCScene* scene();

	// a selector callback
	virtual void menuCloseCallback(CCObject* pSender);

	// implement the "static node()" method manually
	LAYER_NODE_FUNC(HelloWorld);
};

#endif // __HELLOWORLD_SCENE_H__


code:
//
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
//

#ifdef __OBJC__
	#import <Foundation/Foundation.h>
	#import <UIKit/UIKit.h>
#endif


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ancestors</key>
	<array>
		<string>org.cocos2d-x.bundlebase</string>
		<string>org.cocos2d-x.iosbase</string>
		<string>org.cocos2d-x.libcocos2dx</string>
        <string>org.cocos2d-x.libcocosdenshion</string>
	</array>
	<key>Concrete</key>
	<true/>
	<key>Definitions</key>
	<dict>
		<key>Classes/AppDelegate.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.cpp</string>
		</dict>
		<key>Classes/AppDelegate.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Classes/HelloWorldScene.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.cpp</string>
		</dict>
		<key>Classes/HelloWorldScene.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.mm</string>
		</dict>
		<key>ios/main.m</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/main.m</string>
		</dict>
        <key>ios/RootViewController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.mm</string>
		</dict>
        <key>ios/RootViewController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.h</string>
            <key>TargetIndices</key>
			<array/>
		</dict>
		<key>Prefix.pch</key>
		<dict>
			<key>Group</key>
			<string>Supporting Files</string>
			<key>Path</key>
			<string>Prefix.pch</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
	</dict>
	<key>Description</key>
	<string>This template provides a starting point for an application that uses cocos2d-x for iOS, including CocosDenshion </string>
	<key>Identifier</key>
	<string>org.cocos2d-x.cocos2dxOnlyIOSTemplate</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Nodes</key>
	<array>
		<string>Prefix.pch</string>
		<string>ios/main.m</string>
		<string>ios/AppController.h</string>
		<string>ios/AppController.mm</string>
        <string>ios/RootViewController.h</string>
        <string>ios/RootViewController.mm</string>
		<string>Classes/AppDelegate.h</string>
		<string>Classes/AppDelegate.cpp</string>
		<string>Classes/HelloWorldScene.h</string>
		<string>Classes/HelloWorldScene.cpp</string>
	</array>
	<key>Options</key>
	<array>
		<dict>
			<key>Identifier</key>
			<string>deviceFamily</string>
			<key>Units</key>
			<dict>
				<key>iPad</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
				<key>iPhone</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

@class RootViewController;

@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
    UIWindow *window;
    RootViewController	*viewController;
}

@end


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.mm
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"

#import "RootViewController.h"

@implementation AppController

#pragma mark -
#pragma mark Application lifecycle

// cocos2d application instance
static AppDelegate s_sharedApplication;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
                                     pixelFormat: kEAGLColorFormatRGBA8
                                     depthFormat: GL_DEPTH_COMPONENT16_OES
                              preserveBackbuffer: NO
                                      sharegroup: nil
                                   multiSampling: NO
                                 numberOfSamples: 0 ];

    // Use RootViewController manage EAGLView
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = __glView;

    // Set RootViewController to window
    [window addSubview: viewController.view];
    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden: YES];

    cocos2d::CCApplication::sharedApplication().run();
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
	cocos2d::CCDirector::sharedDirector()->pause();
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
	cocos2d::CCDirector::sharedDirector()->resume();
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    cocos2d::CCApplication::sharedApplication().applicationDidEnterBackground();
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
    cocos2d::CCApplication::sharedApplication().applicationWillEnterForeground();
}

- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
     cocos2d::CCDirector::sharedDirector()->purgeCachedData();
}

- (void)dealloc {
    [super dealloc];
}

@end


code:
/****************************************************************************
 Copyright (c) 2010-2011 cocos2d-x.org
 Copyright (c) 2010      Ricardo Quesada

 http://www.cocos2d-x.org

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController {

}

@end


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import "RootViewController.h"

@implementation RootViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

*/
// Override to allow orientations other than the default landscape orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return UIInterfaceOrientationIsLandscape( interfaceOrientation );

    // switch to this line if you want to set portrait view
    // return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

@end


code:
//
//  main.m
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
    [pool release];
    return retVal;
}


code:
//
//  HelloWorldScene.cpp
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"

using namespace cocos2d;
using namespace CocosDenshion;

#define PTM_RATIO 32
enum
{
	kTagTileMap = 1,
	kTagSpriteManager = 1,
	kTagAnimation1 = 1,
};

HelloWorld::HelloWorld()
{
	setIsTouchEnabled( true );
	setIsAccelerometerEnabled( true );

	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
	//UXLOG(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height);

	// Define the gravity vector.
	b2Vec2 gravity;
	gravity.Set(0.0f, -10.0f);

	// Do we want to let bodies sleep?
	bool doSleep = true;

	// Construct a world object, which will hold and simulate the rigid bodies.
	world = new b2World(gravity);
    world->SetAllowSleeping(doSleep);
	world->SetContinuousPhysics(true);

    /*
     m_debugDraw = new GLESDebugDraw( PTM_RATIO );
     world->SetDebugDraw(m_debugDraw);

     uint flags = 0;
     flags += b2DebugDraw::e_shapeBit;
     flags += b2DebugDraw::e_jointBit;
     flags += b2DebugDraw::e_aabbBit;
     flags += b2DebugDraw::e_pairBit;
     flags += b2DebugDraw::e_centerOfMassBit;
     m_debugDraw->SetFlags(flags);
     */

	b2BodyDef groundBodyDef;
	groundBodyDef.position.Set(screenSize.width/2/PTM_RATIO,
                               screenSize.height/2/PTM_RATIO); // bottom-left corner

	// Call the body factory which allocates memory for the ground body
	// from a pool and creates the ground box shape (also from a pool).
	// The body is also added to the world.
	b2Body* groundBody = world->CreateBody(&groundBodyDef);

	// Define the ground box shape.
	b2PolygonShape groundBox;

    // bottom
    groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, -screenSize.height/2/PTM_RATIO), 0);
 	groundBody->CreateFixture(&groundBox, 0);

    // top
    groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, screenSize.height/2/PTM_RATIO), 0);
    groundBody->CreateFixture(&groundBox, 0);

    // left
    groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(-screenSize.width/2/PTM_RATIO, 0), 0);
    groundBody->CreateFixture(&groundBox, 0);

    // right
    groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(screenSize.width/2/PTM_RATIO, 0), 0);
    groundBody->CreateFixture(&groundBox, 0);

	//Set up sprite
	CCSpriteBatchNode *mgr = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 150);
	addChild(mgr, 0, kTagSpriteManager);

	addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) );

	CCLabelTTF *label = CCLabelTTF::labelWithString("Tap screen", "Marker Felt", 32);
	addChild(label, 0);
	label->setColor( ccc3(0,0,255) );
	label->setPosition( CCPointMake( screenSize.width/2, screenSize.height-50) );

	schedule( schedule_selector(HelloWorld::tick) );
}

HelloWorld::~HelloWorld()
{
	delete world;
	world = NULL;

	//delete m_debugDraw;
}

void HelloWorld::draw()
{
	// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	// Needed states:  GL_VERTEX_ARRAY,
	// Unneeded states: GL_TEXTURE_2D, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	//world->DrawDebugData();

	// restore default GL states
	glEnable(GL_TEXTURE_2D);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}

void HelloWorld::addNewSpriteWithCoords(CCPoint p)
{
	//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
	CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);

	//We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
	//just randomly picking one of the images
	int idx = (CCRANDOM_0_1() > .5 ? 0:1);
	int idy = (CCRANDOM_0_1() > .5 ? 0:1);

	CCSprite *sprite = CCSprite::spriteWithBatchNode(sheet, CCRectMake(32 * idx,32 * idy,32,32));
	sheet->addChild(sprite);

	sprite->setPosition( CCPointMake( p.x, p.y) );

	// Define the dynamic body.
	//Set up a 1m squared box in the physics world
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
	bodyDef.userData = sprite;
	b2Body *body = world->CreateBody(&bodyDef);

	// Define another box shape for our dynamic body.
	b2PolygonShape dynamicBox;
	dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box

	// Define the dynamic body fixture.
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &dynamicBox;
	fixtureDef.density = 1.0f;
	fixtureDef.friction = 0.3f;
	body->CreateFixture(&fixtureDef);
}

void HelloWorld::tick(ccTime dt)
{
	//It is recommended that a fixed time step is used with Box2D for stability
	//of the simulation, however, we are using a variable time step here.
	//You need to make an informed choice, the following URL is useful
	//http://gafferongames.com/game-physics/fix-your-timestep/

	int velocityIterations = 8;
	int positionIterations = 1;

	// Instruct the world to perform a single step of simulation. It is
	// generally best to keep the time step and iterations fixed.
	world->Step(dt, velocityIterations, positionIterations);

	//Iterate over the bodies in the physics world
	for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
	{
		if (b->GetUserData() != NULL) {
			//Synchronize the AtlasSprites position and rotation with the corresponding body
			CCSprite* myActor = (CCSprite*)b->GetUserData();
			myActor->setPosition( CCPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) );
			myActor->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) );
		}
	}
}

void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	//Add a new body/atlas sprite at the touched location
	CCSetIterator it;
	CCTouch* touch;

	for( it = touches->begin(); it != touches->end(); it++)
	{
		touch = (CCTouch*)(*it);

		if(!touch)
			break;

		CCPoint location = touch->locationInView();

		location = CCDirector::sharedDirector()->convertToGL(location);

		addNewSpriteWithCoords( location );
	}
}

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::node();

    // add layer as a child to scene
    CCLayer* layer = new HelloWorld();
    scene->addChild(layer);
    layer->release();

    return scene;
}


code:
//
//  HelloWorldScene.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#ifndef __HELLO_WORLD_H__
#define __HELLO_WORLD_H__

// When you import this file, you import all the cocos2d classes
#include "cocos2d.h"
#include "Box2D.h"

class HelloWorld : public cocos2d::CCLayer {
public:
    ~HelloWorld();
    HelloWorld();

    // returns a Scene that contains the HelloWorld as the only child
    static cocos2d::CCScene* scene();

    // adds a new sprite at a given coordinate
    void addNewSpriteWithCoords(cocos2d::CCPoint p);
    virtual void draw();
    virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
    void tick(cocos2d::ccTime dt);

private:
    b2World* world;
};

#endif // __HELLO_WORLD_H__


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleDisplayName</key>
	<string>${PRODUCT_NAME}</string>
	<key>CFBundleExecutable</key>
	<string>${EXECUTABLE_NAME}</string>
	<key>CFBundleIconFile</key>
	<string></string>
	<key>Icon files</key>
	<array>
		<string>Icon.png</string>
		<string>Icon@2x.png</string>
		<string>Icon-72.png</string>
		<string>Icon-Small-50.png</string>
		<string>Icon-Small.png</string>
		<string>Icon-Small@2x.png</string>
	</array>
	<key>CFBundleIdentifier</key>
	<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>${PRODUCT_NAME}</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1.0</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIPrerenderedIcon</key>
	<true/>
	<key>UIStatusBarHidden</key>
	<true/>
	<key>UIRequiredDeviceCapabilities</key>
	<dict>
		<key>accelerometer</key>
		<true/>
		<key>opengles-1</key>
		<true/>
	</dict>
</dict>
</plist>


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ancestors</key>
	<array>
		<string>org.cocos2d-x.bundlebase</string>
		<string>org.cocos2d-x.iosbase</string>
		<string>org.cocos2d-x.libcocos2dx</string>
		<string>org.cocos2d-x.libcocosdenshion</string>
		<string>org.cocos2d-x.libbox2d</string>
	</array>
	<key>Concrete</key>
	<true/>
	<key>Definitions</key>
	<dict>
		<key>Classes/AppDelegate.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.cpp</string>
		</dict>
		<key>Classes/AppDelegate.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Classes/HelloWorldScene.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.cpp</string>
		</dict>
		<key>Classes/HelloWorldScene.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.mm</string>
		</dict>
		<key>ios/main.m</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/main.m</string>
		</dict>
		<key>ios/RootViewController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/RootViewController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.mm</string>
		</dict>
		<key>Prefix.pch</key>
		<dict>
			<key>Group</key>
			<string>Supporting Files</string>
			<key>Path</key>
			<string>Prefix.pch</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Resources/blocks.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/blocks.png</string>
		</dict>
	</dict>
	<key>Description</key>
	<string>This template provides a starting point for an application that uses cocos2d and Box2d for iOS. It includes CocosDenshion, FontLabel and cocosLive.</string>
	<key>Identifier</key>
	<string>org.cocos2d-x.cocos2dxBox2dIOSTemplate</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Nodes</key>
	<array>
		<string>Prefix.pch</string>
		<string>ios/main.m</string>
		<string>ios/AppController.h</string>
		<string>ios/AppController.mm</string>
        <string>ios/RootViewController.h</string>
        <string>ios/RootViewController.mm</string>
		<string>Classes/AppDelegate.h</string>
		<string>Classes/AppDelegate.cpp</string>
		<string>Classes/HelloWorldScene.h</string>
		<string>Classes/HelloWorldScene.cpp</string>
		<string>Resources/blocks.png</string>
	</array>
	<key>Options</key>
	<array>
		<dict>
			<key>Identifier</key>
			<string>deviceFamily</string>
			<key>Units</key>
			<dict>
				<key>iPad</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
				<key>iPhone</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
			</dict>
		</dict>
	</array>
	<key>Targets</key>
	<array>
		<dict>
			<key>SharedSettings</key>
			<dict>
				<key>ALWAYS_SEARCH_USER_PATHS</key>
				<string>YES</string>
				<key>USER_HEADER_SEARCH_PATHS</key>
				<string>"___PACKAGENAME___/libs"</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.mm
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"

#import "RootViewController.h"

@implementation AppController

#pragma mark -
#pragma mark Application lifecycle

// cocos2d application instance
static AppDelegate s_sharedApplication;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
                                     pixelFormat: kEAGLColorFormatRGBA8
                                     depthFormat: GL_DEPTH_COMPONENT16_OES
						      preserveBackbuffer: NO
                                      sharegroup: nil
								   multiSampling: NO
								 numberOfSamples:0 ];

    // Use RootViewController manage EAGLView
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = __glView;

    // Set RootViewController to window
    [window addSubview:__glView];
    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden: YES];

    cocos2d::CCApplication::sharedApplication().run();
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
	cocos2d::CCDirector::sharedDirector()->pause();
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
	cocos2d::CCDirector::sharedDirector()->resume();
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    cocos2d::CCApplication::sharedApplication().applicationDidEnterBackground();
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
    cocos2d::CCApplication::sharedApplication().applicationWillEnterForeground();
}

- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
     cocos2d::CCDirector::sharedDirector()->purgeCachedData();
}

- (void)dealloc {
    [super dealloc];
}

@end


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController {

}

@end


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#include "AppDelegate.h"

#include "cocos2d.h"
#include "HelloWorldScene.h"

USING_NS_CC;

AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::initInstance()
{
    bool bRet = false;
    do
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView * pMainWnd = new CCEGLView();
        CC_BREAK_IF(! pMainWnd
            || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));

#endif  // CC_PLATFORM_WIN32

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        // OpenGLView is initialized in AppDelegate.mm on ios platform, nothing need to do here.
#endif  // CC_PLATFORM_IOS

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        // OpenGLView is initialized in HelloWorld/android/jni/helloworld/main.cpp
		// the default setting is to create a fullscreen view
		// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
#endif  // CC_PLATFORM_ANDROID

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView* pMainWnd = new CCEGLView(this);
        CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));

#ifndef _TRANZDA_VM_
        // on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
        cocos2d::CCFileUtils::setResource("HelloWorld.zip");
#endif

#endif  // CC_PLATFORM_WOPHONE

#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
		// MaxAksenov said it's NOT a very elegant solution. I agree, haha
		CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif

        bRet = true;
    } while (0);
    return bRet;
}

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    // pDirector->enableRetinaDisplay(true);

	// sets landscape mode
	// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);

	// turn on display FPS
	pDirector->setDisplayFPS(true);

	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);

	// create a scene. it's an autorelease object
	CCScene *pScene = HelloWorld::scene();

	// run
	pDirector->runWithScene(pScene);

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

	// if you use SimpleAudioEngine, it must be pause
	// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();

	// if you use SimpleAudioEngine, it must resume here
	// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "CCApplication.h"

/**
@brief	The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class  AppDelegate : private cocos2d::CCApplication
{
public:
	AppDelegate();
	virtual ~AppDelegate();

    /**
    @brief	Implement for initialize OpenGL instance, set source path, etc...
    */
    virtual bool initInstance();

    /**
    @brief	Implement CCDirector and CCScene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();

    /**
    @brief  The function be called when the application enter background
    @param  the pointer of the application
    */
    virtual void applicationDidEnterBackground();

    /**
    @brief  The function be called when the application enter foreground
    @param  the pointer of the application
    */
    virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_


code:
//
//  HelloWorldScene.cpp
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"

using namespace cocos2d;
using namespace CocosDenshion;

enum {
	kTagBatchNode = 1,
};

static void
eachShape(void *ptr, void* unused)
{
        cpShape *shape = (cpShape*) ptr;
        CCSprite *sprite = (CCSprite*)shape->data;
        if( sprite )
        {
                cpBody *body = shape->body;

                // TIP: cocos2d and chipmunk uses the same struct to store it's position
                // chipmunk uses: cpVect, and cocos2d uses CGPoint but in reality the are the same
                // since v0.7.1 you can mix them if you want.
                sprite->setPosition(CCPointMake(body->p.x, body->p.y));

                sprite->setRotation((float) CC_RADIANS_TO_DEGREES( -body->a ));
        }
}

HelloWorld::HelloWorld()
{
}

HelloWorld::~HelloWorld()
{
}

CCScene* HelloWorld::scene()
{
        // 'scene' is an autorelease object.
        CCScene *scene = CCScene::node();

        // 'layer' is an autorelease object.
        HelloWorld *layer = HelloWorld::node();

        // add layer as a child to scene
        scene->addChild(layer);

        // return the scene
        return scene;
}

void HelloWorld::addNewSpriteX(float x,  float y)
{
        int posx, posy;

        CCSpriteBatchNode *batch = (CCSpriteBatchNode*) getChildByTag(kTagBatchNode);

        posx = (CCRANDOM_0_1() * 200);
        posy = (CCRANDOM_0_1() * 200);

        posx = (posx % 4) * 85;
        posy = (posy % 3) * 121;

        CCSprite *sprite = CCSprite::spriteWithBatchNode(batch, CCRectMake(posx, posy, 85, 121));
        batch->addChild(sprite);

        sprite->setPosition(ccp(x, y));

        int num = 4;
        cpVect verts[] = {
                cpv(-24,-54),
                cpv(-24, 54),
                cpv( 24, 54),
                cpv( 24,-54),
        };

        cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpv(0, 0)));

        // TIP:
        // since v0.7.1 you can assign CGPoint to chipmunk instead of cpVect.
        // cpVect == CGPoint
        body->p = cpv(x, y);
        cpSpaceAddBody(space, body);

        cpShape* shape = cpPolyShapeNew(body, num, verts, cpv(0, 0));
        shape->e = 0.5f; shape->u = 0.5f;
        shape->data = sprite;
        cpSpaceAddShape(space, shape);
}

bool HelloWorld::init()
{
        bool ret = false;

        if (ret = CCLayer::init())
        {
                setIsTouchEnabled(true);

                CCSize wins = CCDirector::sharedDirector()->getWinSize();
                cpInitChipmunk();

                cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
                space = cpSpaceNew();
                cpSpaceResizeStaticHash(space, 400.0f, 40);
                cpSpaceResizeActiveHash(space, 100, 600);

                space->gravity = cpv(0, 0);
                space->elasticIterations = space->iterations;

                cpShape *shape;

                // bottom
                shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(wins.width,0), 0.0f);
                shape->e = 1.0f; shape->u = 1.0f;
                cpSpaceAddStaticShape(space, shape);

                // top
                shape = cpSegmentShapeNew(staticBody, cpv(0,wins.height), cpv(wins.width,wins.height), 0.0f);
                shape->e = 1.0f; shape->u = 1.0f;
                cpSpaceAddStaticShape(space, shape);

                // left
                shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,wins.height), 0.0f);
                shape->e = 1.0f; shape->u = 1.0f;
                cpSpaceAddStaticShape(space, shape);

                // right
                shape = cpSegmentShapeNew(staticBody, cpv(wins.width,0), cpv(wins.width,wins.height), 0.0f);
                shape->e = 1.0f; shape->u = 1.0f;
                cpSpaceAddStaticShape(space, shape);

                CCSpriteBatchNode *batch = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 100);
                addChild(batch, 0, kTagBatchNode);

                addNewSpriteX(200, 200);

                schedule(schedule_selector(HelloWorld::step));
        }

        return ret;
}

void HelloWorld::onEnter()
{
        CCLayer::onEnter();
}

void HelloWorld::step(ccTime delta)
{
        int steps = 2;
        CGFloat dt = delta/(CGFloat)steps;

        for(int i=0; i<steps; i++)
        {
                cpSpaceStep(space, dt);
        }
        cpSpaceHashEach(space->activeShapes, &eachShape, NULL);
        cpSpaceHashEach(space->staticShapes, &eachShape, NULL);
}

void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event)
{
        CCSetIterator it;
        CCTouch *touch;

        for (it = touches->begin(); it != touches->end(); it++) {
                touch = (CCTouch*)(*it);

                if (! touch) {
                        break;
                }

                CCPoint location = touch->locationInView();
                location = CCDirector::sharedDirector()->convertToGL(location);
                addNewSpriteX(location.x, location.y);
        }
}


code:
//
//  HelloWorldScene.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#ifndef __HELLOW_WORLD_H__
#define __HELLOW_WORLD_H__

#include "cocos2d.h"

// include Chipmunk headers
#include "chipmunk.h"

// HelloWorld Layer
class HelloWorld : public cocos2d::CCLayer {
public:
        HelloWorld();
        ~HelloWorld();

        static cocos2d::CCScene* scene();
        void step(cocos2d::ccTime dt);
        void addNewSpriteX(float x, float y);
        virtual void onEnter();
        virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent *event);

        LAYER_NODE_FUNC(HelloWorld);

private:
        bool init();
        cpSpace *space;
};

#endif // __HELLOW_WORLD_H__


code:
//
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
//

#ifdef __OBJC__
	#import <Foundation/Foundation.h>
	#import <UIKit/UIKit.h>
#endif


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ancestors</key>
	<array>
		<string>org.cocos2d-x.bundlebase</string>
		<string>org.cocos2d-x.iosbase</string>
		<string>org.cocos2d-x.libcocos2dx</string>
		<string>org.cocos2d-x.libcocosdenshion</string>
		<string>org.cocos2d-x.libchipmunk</string>
	</array>
	<key>Concrete</key>
	<true/>
	<key>Definitions</key>
	<dict>
		<key>Classes/AppDelegate.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.cpp</string>
		</dict>
		<key>Classes/AppDelegate.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Classes/HelloWorldScene.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.cpp</string>
		</dict>
		<key>Classes/HelloWorldScene.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/HelloWorldScene.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.mm</string>
		</dict>
		<key>ios/main.m</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/main.m</string>
		</dict>
		<key>ios/RootViewController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/RootViewController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.mm</string>
		</dict>
		<key>Prefix.pch</key>
		<dict>
			<key>Group</key>
			<string>Supporting Files</string>
			<key>Path</key>
			<string>Prefix.pch</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Resources/grossini_dance_atlas.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/grossini_dance_atlas.png</string>
		</dict>
	</dict>
	<key>Description</key>
	<string>This template provides a starting point for an application that uses cocos2d and Chipmunk for iOS. It includes CocosDenshion, FontLabel and cocosLive.</string>
	<key>Identifier</key>
	<string>org.cocos2d-x.cocos2dxChipmunkIOSTemplate</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Nodes</key>
	<array>
		<string>Prefix.pch</string>
		<string>ios/main.m</string>
		<string>ios/AppController.h</string>
		<string>ios/AppController.mm</string>
        <string>ios/RootViewController.h</string>
        <string>ios/RootViewController.mm</string>
		<string>Classes/AppDelegate.h</string>
		<string>Classes/AppDelegate.cpp</string>
		<string>Classes/HelloWorldScene.h</string>
		<string>Classes/HelloWorldScene.cpp</string>
		<string>Resources/grossini_dance_atlas.png</string>
	</array>
	<key>Options</key>
	<array>
		<dict>
			<key>Identifier</key>
			<string>deviceFamily</string>
			<key>Units</key>
			<dict>
				<key>iPad</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
				<key>iPhone</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
			</dict>
		</dict>
	</array>
	<key>Targets</key>
	<array>
		<dict>
			<key>SharedSettings</key>
			<dict>
				<key>ALWAYS_SEARCH_USER_PATHS</key>
				<string>YES</string>
				<key>USER_HEADER_SEARCH_PATHS</key>
				<string>"___PACKAGENAME___/libs/Chipmunk/include/chipmunk"</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.h
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

@class RootViewController;

@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
    UIWindow *window;
    RootViewController	*viewController;
}

@end


code:
//
//  ___PROJECTNAMEASIDENTIFIER___AppController.mm
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"

#import "RootViewController.h"

@implementation AppController

#pragma mark -
#pragma mark Application lifecycle

// cocos2d application instance
static AppDelegate s_sharedApplication;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
                                     pixelFormat: kEAGLColorFormatRGBA8
                                     depthFormat: GL_DEPTH_COMPONENT16_OES
                              preserveBackbuffer: NO
                                      sharegroup: nil
                                   multiSampling: NO
                                 numberOfSamples: 0 ];

    // Use RootViewController manage EAGLView
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = __glView;

    // Set RootViewController to window
    [window addSubview:__glView];
    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden: YES];

    cocos2d::CCApplication::sharedApplication().run();
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
	cocos2d::CCDirector::sharedDirector()->pause();
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
	cocos2d::CCDirector::sharedDirector()->resume();
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    cocos2d::CCApplication::sharedApplication().applicationDidEnterBackground();
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
    cocos2d::CCApplication::sharedApplication().applicationWillEnterForeground();
}

- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
     cocos2d::CCDirector::sharedDirector()->purgeCachedData();
}

- (void)dealloc {
    [super dealloc];
}

@end


code:
#include "cocos2d.h"
#include "AppDelegate.h"
#include "SimpleAudioEngine.h"
#include "CCScriptSupport.h"
#include "CCLuaEngine.h"

#define IPAD		0

#if IPAD
#define CC_WIDTH	1024
#define CC_HEIGHT	768
#elif IPHONE_4
#define CC_WIDTH	960
#define CC_HEIGHT	640
#else
#define CC_WIDTH	480
#define CC_HEIGHT	320
#endif

USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate()
{
	// fixed me
	//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
}

AppDelegate::~AppDelegate()
{
	// end simple audio engine here, or it may crashed on win32
	SimpleAudioEngine::sharedEngine()->end();
    CCScriptEngineManager::purgeSharedManager();
}

bool AppDelegate::initInstance()
{
    bool bRet = false;
    do
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView * pMainWnd = new CCEGLView();
        CC_BREAK_IF(! pMainWnd
            || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), CC_WIDTH, CC_HEIGHT));

#endif  // CC_PLATFORM_WIN32

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

        // OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.

#endif  // CC_PLATFORM_IOS

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

		// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
		// the default setting is to create a fullscreen view
		// if you want to use auto-scale, please enable view->create(320,480) in main.cpp

#endif  // CC_PLATFORM_ANDROID

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)

        // Initialize OpenGLView instance, that release by CCDirector when application terminate.
        // The HelloWorld is designed as HVGA.
        CCEGLView* pMainWnd = new CCEGLView(this);
        CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));

#ifndef _TRANZDA_VM_
        // on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
        cocos2d::CCFileUtils::setResource("HelloWorld.zip");
#endif

#endif  // CC_PLATFORM_WOPHONE

#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
		// MaxAksenov said it's NOT a very elegant solution. I agree, haha
		CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
        bRet = true;
    } while (0);
    return bRet;
}

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    // pDirector->enableRetinaDisplay(true);

	// turn on display FPS
	pDirector->setDisplayFPS(true);

	// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);

	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);

	// register lua engine
    CCScriptEngineProtocol* pEngine = CCLuaEngine::engine();
    CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	unsigned long size;
	char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);

	if (pFileContent)
	{
	    // copy the file contents and add '\0' at the end, or the lua parser can not parse it
	    char *pCodes = new char[size + 1];
	    pCodes[size] = '\0';
	    memcpy(pCodes, pFileContent, size);
	    delete[] pFileContent;

	    pEngine->executeString(pCodes);
	    delete []pCodes;
	}
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
	string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
    pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
    pEngine->executeScriptFile(path.c_str());
#endif

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

	// if you use SimpleAudioEngine, it must be pause
	// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();

	// if you use SimpleAudioEngine, it must resume here
	// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}


code:
#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "CCApplication.h"

/**
@brief	The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class  AppDelegate : private cocos2d::CCApplication
{
public:
	AppDelegate();
	virtual ~AppDelegate();

    /**
    @brief	Implement for initialize OpenGL instance, set source path, etc...
    */
    virtual bool initInstance();

    /**
    @brief	Implement CCDirector and CCScene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();

    /**
    @brief  The function be called when the application enter background
    @param  the pointer of the application
    */
    virtual void applicationDidEnterBackground();

    /**
    @brief  The function be called when the application enter foreground
    @param  the pointer of the application
    */
    virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_


code:
-- avoid memory leak
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)

local cclog = function(...)
    print(string.format(...))
end

require "hello2"
cclog("result is " .. myadd(3, 5))

---------------

local winSize = CCDirector:sharedDirector():getWinSize()

-- add the moving dog
local function creatDog()
    local frameWidth = 105
    local frameHeight = 95

    -- create dog animate
    local textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png")
    local rect = CCRectMake(0, 0, frameWidth, frameHeight)
    local frame0 = CCSpriteFrame:frameWithTexture(textureDog, rect)
    rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight)
    local frame1 = CCSpriteFrame:frameWithTexture(textureDog, rect)

    local spriteDog = CCSprite:spriteWithSpriteFrame(frame0)
    spriteDog.isPaused = false
    spriteDog:setPosition(0, winSize.height / 4 * 3)

    local animFrames = CCMutableArray_CCSpriteFrame__:new(2)
    animFrames:addObject(frame0)
    animFrames:addObject(frame1)

    local animation = CCAnimation:animationWithFrames(animFrames, 0.5)
    local animate = CCAnimate:actionWithAnimation(animation, false);
    spriteDog:runAction(CCRepeatForever:actionWithAction(animate))

    -- moving dog at every frame
    local function tick()
        if spriteDog.isPaused then return end
        local x, y = spriteDog:getPosition()
        if x > winSize.width then
            x = 0
        else
            x = x + 1
        end
        spriteDog:setPositionX(x)
    end

    CCScheduler:sharedScheduler():scheduleScriptFunc(tick, 0, false)

    return spriteDog
end

-- create farm
local function createLayerFram()
    local layerFarm = CCLayer:node()

    -- add in farm background
    local bg = CCSprite:spriteWithFile("farm.jpg")
    bg:setPosition(winSize.width / 2 + 80, winSize.height / 2)
    layerFarm:addChild(bg)

    -- add land sprite
    for i = 0, 3 do
        for j = 0, 1 do
            local spriteLand = CCSprite:spriteWithFile("land.png")
            spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2)
            layerFarm:addChild(spriteLand)
        end
    end

    -- add crop
    local textureCrop = CCTextureCache:sharedTextureCache():addImage("crop.png")
    local frameCrop = CCSpriteFrame:frameWithTexture(textureCrop, CCRectMake(0, 0, 105, 95))
    for i = 0, 3 do
        for j = 0, 1 do
            local spriteCrop = CCSprite:spriteWithSpriteFrame(frameCrop);
            spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2)
            layerFarm:addChild(spriteCrop)
        end
    end

    -- add moving dog
    local spriteDog = creatDog()
    layerFarm:addChild(spriteDog)

    -- handing touch events
    local touchBeginPoint = nil

    local function onTouchBegan(x, y)
        cclog("onTouchBegan: %0.2f, %0.2f", x, y)
        touchBeginPoint = {x = x, y = y}
        spriteDog.isPaused = true
        -- CCTOUCHBEGAN event must return true
        return true
    end

    local function onTouchMoved(x, y)
        cclog("onTouchMoved: %0.2f, %0.2f", x, y)
        if touchBeginPoint then
            local cx, cy = layerFarm:getPosition()
            layerFarm:setPosition(cx + x - touchBeginPoint.x,
                                  cy + y - touchBeginPoint.y)
            touchBeginPoint = {x = x, y = y}
        end
    end

    local function onTouchEnded(x, y)
        cclog("onTouchEnded")
        touchBeginPoint = nil
        spriteDog.isPaused = false
    end

    local function onTouch(eventType, x, y)
        if eventType == CCTOUCHBEGAN then
            return onTouchBegan(x, y)
        elseif eventType == CCTOUCHMOVED then
            return onTouchMoved(x, y)
        else
            return onTouchEnded(x, y)
        end
    end

    layerFarm:registerScriptTouchHandler(onTouch)
    layerFarm:setIsTouchEnabled(true)

    return layerFarm
end

-- create menu
local function createLayerMenu()
    local layerMenu = CCLayer:node()

    local menuPopup, menuTools, effectID

    local function menuCallbackClosePopup()
        -- stop test sound effect
        SimpleAudioEngine:sharedEngine():stopEffect(effectID)
        menuPopup:setIsVisible(false)
    end

    local function menuCallbackOpenPopup()
        -- loop test sound effect
        effectID = SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
        menuPopup:setIsVisible(true)
    end

    -- add a popup menu
    local menuPopupItem = CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
    menuPopupItem:setPosition(0, 0)
    menuPopupItem:registerScriptHandler(menuCallbackClosePopup)
    menuPopup = CCMenu:menuWithItem(menuPopupItem)
    menuPopup:setPosition(winSize.width / 2, winSize.height / 2)
    menuPopup:setIsVisible(false)
    layerMenu:addChild(menuPopup)

    -- add the left-bottom "tools" menu to invoke menuPopup
    local menuToolsItem = CCMenuItemImage:itemFromNormalImage("menu1.png", "menu1.png")
    menuToolsItem:setPosition(0, 0)
    menuToolsItem:registerScriptHandler(menuCallbackOpenPopup)
    menuTools = CCMenu:menuWithItem(menuToolsItem)
    menuTools:setPosition(30, 40)
    layerMenu:addChild(menuTools)

    return layerMenu
end

-- play background music, preload effect
SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");

-- run
local sceneGame = CCScene:node()
sceneGame:addChild(createLayerFram())
sceneGame:addChild(createLayerMenu())
CCDirector:sharedDirector():runWithScene(sceneGame)


code:
function myadd(x, y)
    return x + y
end


code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ancestors</key>
	<array>
		<string>org.cocos2d-x.bundlebase</string>
		<string>org.cocos2d-x.iosbase</string>
		<string>org.cocos2d-x.libcocos2dx</string>
		<string>org.cocos2d-x.libcocosdenshion</string>
		<string>org.cocos2d-x.liblua</string>
	</array>
	<key>Concrete</key>
	<true/>
	<key>Definitions</key>
	<dict>
		<key>Classes/AppDelegate.cpp</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.cpp</string>
		</dict>
		<key>Classes/AppDelegate.h</key>
		<dict>
			<key>Group</key>
			<string>Classes</string>
			<key>Path</key>
			<string>Classes/AppDelegate.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>ios/AppController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/AppController.mm</string>
		</dict>
		<key>ios/main.m</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/main.m</string>
		</dict>
		<key>ios/RootViewController.mm</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.mm</string>
		</dict>
		<key>ios/RootViewController.h</key>
		<dict>
			<key>Group</key>
			<string>ios</string>
			<key>Path</key>
			<string>ios/RootViewController.h</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Prefix.pch</key>
		<dict>
			<key>Group</key>
			<string>Supporting Files</string>
			<key>Path</key>
			<string>Prefix.pch</string>
			<key>TargetIndices</key>
			<array/>
		</dict>
		<key>Resources/farm.jpg</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/farm.jpg</string>
		</dict>
		<key>Resources/crop.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/crop.png</string>
		</dict>
		<key>Resources/dog.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/dog.png</string>
		</dict>
		<key>Resources/hello.lua</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/hello.lua</string>
		</dict>
		<key>Resources/hello2.lua</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/hello2.lua</string>
		</dict>
		<key>Resources/land.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/land.png</string>
		</dict>
		<key>Resources/menu1.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/menu1.png</string>
		</dict>
		<key>Resources/menu2.png</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/menu2.png</string>
		</dict>
		<key>Resources/background.mp3</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/background.mp3</string>
		</dict>
		<key>Resources/effect1.wav</key>
		<dict>
			<key>Group</key>
			<string>Resources</string>
			<key>Path</key>
			<string>Resources/effect1.wav</string>
		</dict>
	</dict>
	<key>Description</key>
	<string>This template provides a starting point for an application that uses cocos2d-x for iOS, including CocosDenshion </string>
	<key>Identifier</key>
	<string>org.cocos2d-x.cocos2dxLuaIOSTemplate</string>
	<key>Kind</key>
	<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
	<key>Nodes</key>
	<array>
		<string>Prefix.pch</string>
		<string>ios/main.m</string>
		<string>ios/AppController.h</string>
		<string>ios/AppController.mm</string>
		<string>ios/RootViewController.h</string>
		<string>ios/RootViewController.mm</string>
		<string>Classes/AppDelegate.h</string>
		<string>Classes/AppDelegate.cpp</string>
		<string>Resources/farm.jpg</string>
		<string>Resources/crop.png</string>
		<string>Resources/dog.png</string>
		<string>Resources/hello.lua</string>
		<string>Resources/hello2.lua</string>
		<string>Resources/land.png</string>
		<string>Resources/menu1.png</string>
		<string>Resources/menu2.png</string>
		<string>Resources/background.mp3</string>
		<string>Resources/effect1.wav</string>
	</array>
	<key>Options</key>
	<array>
		<dict>
			<key>Identifier</key>
			<string>deviceFamily</string>
			<key>Units</key>
			<dict>
				<key>iPad</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
				<key>iPhone</key>
				<dict>
					<key>Definitions</key>
					<dict/>
				</dict>
			</dict>
		</dict>
	</array>
</dict>
</plist>