在 Mac 上制作一个 simulator
我们在使用 cocos2d-lua 的时候可以 在新建的工程里面 用 cocos run -p -mac 运行项目看看效果,但是要是每次都用这个方法的话会比较的麻烦.等待的时间会比较的长,lua 代码是不必要去 编译的. 那么有没有一种方法可以方便的去刷新查看我们修改的结果效果呢.当然有.
- 我们可以用 Xcode 编译一个.cpp 出来.在 proj.ios_mac里面启动工程.
- 根据图片配置好Xcode的文件,注意去掉 res 和 src 文件 是让其不打在 包里达到 及时刷新作用
- 去掉了 res 和 src 那么我们的 工程在 运行的时候需要去 哪里 找 lua 文件 运行呢,自然是找不到了,所以我们需要修改一下 C++ 代码 去让 引擎 找到 操作: 修改SimulatorApp.mm文件 在里面 找到 startup方法 将里面的NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; 修改如下:
- (void) startup
{
FileUtils::getInstance()->setPopupNotify(false);
_project.dump();
const string projectDir = _project.getProjectDir();
if (projectDir.length())
{
FileUtils::getInstance()->setDefaultResourceRootPath(projectDir);
if (_project.isWriteDebugLogToFile())
{
[self writeDebugLogToFile:_project.getDebugLogFilePath()];
}
}
const string writablePath = _project.getWritableRealPath();
if (writablePath.length())
{
FileUtils::getInstance()->setWritablePath(writablePath.c_str());
}
//这里需要修改:
// path for looking Lang file, Studio Default images
// NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
// FileUtils::getInstance()->addSearchPath(resourcePath.UTF8String);
// 修改为如下:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSArray *array = [path componentsSeparatedByString:@"runtime"];
NSString *resourcePath = [array firstObject];
FileUtils::getInstance()->setDefaultResourceRootPath(resourcePath.UTF8String);
// app
_app = new AppDelegate();
[self setupUI];
[self adjustEditMenuIndex];
RuntimeEngine::getInstance()->setProjectConfig(_project);
Application::getInstance()->run();
// After run, application needs to be terminated immediately.
[NSApp terminate: self];
}
- 最后我们 comand + B 编译即可,需要等待一段时间.最后生成一下.app文件,点击运行即可.