我有 3 个类,GamePlay、Util、Panel 在 GamePlay 中,我有很多面板作为矩阵 我想创建一个数组来存储每个面板的类型。类型是 int (为了简单)。 所以我想将该数组存储在 Util 中,然后我也可以更新并从 GamePlay 和 Panel 获取值。
我尝试使用 static int * array[100];但它出错了。
请帮帮我。或者告诉我最好的方法。
感谢您的帮助。
最佳答案
将所有类作为 CCObject
的子类,然后您可以将它们的对象存储在 CCArray
例如您的类(class) Panel
将是:
class Panel : CCObject
{
};
将 Panel
存储在 CCArray
中:
CCArray* array = CCArray::create();
Panel* panel = new Panel();
array.addObject(panel);
关于c++ - cocos2d-x:来自另一个类的 CRUD 二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21128518/