public static void init(final Activity activity) { final ApplicationInfo applicationInfo = activity.getApplicationInfo(); initListener(); try { // Get the lib_name from AndroidManifest.xml metadata ActivityInfo ai = activity .getPackageManager() .getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA); if (null != ai.metaData) { String lib_name = ai.metaData.getString(META_DATA_LIB_NAME); if (null != lib_name) { System.loadLibrary(lib_name); } else { System.loadLibrary(DEFAULT_LIB_NAME); } } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Error getting activity info", e); } Cocos2dxHelper.sPackageName = applicationInfo.packageName; Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); // Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); Cocos2dxHelper.sAssetManager = activity.getAssets(); // Cocos2dxHelper.nativeSetAssetManager(sAssetManager); Cocos2dxBitmap.setContext(activity); sActivity = activity; }
public static void init( final Context pContext, final Cocos2dxHelperListener pCocos2dxHelperListener) { final ApplicationInfo applicationInfo = pContext.getApplicationInfo(); Cocos2dxHelper.sContext = pContext; Cocos2dxHelper.sCocos2dxHelperListener = pCocos2dxHelperListener; Cocos2dxHelper.sPackageName = applicationInfo.packageName; Cocos2dxHelper.sFileDirectory = pContext.getFilesDir().getAbsolutePath(); Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(pContext); Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(pContext); Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(pContext); Cocos2dxHelper.sAssetManager = pContext.getAssets(); Cocos2dxBitmap.setContext(pContext); Cocos2dxETCLoader.setContext(pContext); }
public static void init(final Activity activity) { if (!sInited) { final ApplicationInfo applicationInfo = activity.getApplicationInfo(); Cocos2dxHelper.sCocos2dxHelperListener = (Cocos2dxHelperListener) activity; Cocos2dxHelper.sPackageName = applicationInfo.packageName; Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(activity); Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); Cocos2dxHelper.sAssetManager = activity.getAssets(); Cocos2dxHelper.nativeSetContext((Context) activity, Cocos2dxHelper.sAssetManager); Cocos2dxBitmap.setContext(activity); sActivity = activity; sInited = true; } }