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())。你可以发布你的类的详细信息