Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在扩展CCLayer的类中使用getAssets_Android_Cocos2d Android_Cclayer - Fatal编程技术网

Android 如何在扩展CCLayer的类中使用getAssets

Android 如何在扩展CCLayer的类中使用getAssets,android,cocos2d-android,cclayer,Android,Cocos2d Android,Cclayer,我有一个类扩展了CCLayer。我必须从资产文件夹中获取一个文本文件。但是我不能在这个类中使用getAssets()。如何在扩展了CCLayer的类中使用getAssets()?在类中创建方法时,请使用: private void abc (Context context){ context.getAssets(); } 调用此方法时,必须将上下文放入方法: yourclass.abc(getBaseContext()); 您必须在上下文中传递给类才能使用它。如果它是您的自定义类,请

我有一个类扩展了
CCLayer
。我必须从资产文件夹中获取一个文本文件。但是我不能在这个类中使用
getAssets()
。如何在扩展了
CCLayer
的类中使用
getAssets()

在类中创建方法时,请使用:

private void abc (Context context){
    context.getAssets();
}
调用此方法时,必须将上下文放入方法:

yourclass.abc(getBaseContext());

您必须在上下文中传递给类才能使用它。如果它是您的自定义类,请将其传递到构造函数中,然后按住它并使用它。

最终得到了答案

Context context = CCDirector.sharedDirector().getActivity().getApplicationContext();
InputStream is = context.getAssets().open("abc.txt");

当我尝试使用它时,它给了我一个错误:(尝试新建yourclass.abc(your_activity.this)或新建yourclass.abc(getapplicationcontext())。你可以发布你的类的详细信息