Android App 설정 파일 적용하기

cocos2dx 3.17.1


  • Resources 폴더의 설정 파일 불러오기.
Android에서 게임 시작 시 필요한 정보들을 텍스트 파일에서 불러오려면.
Resources



설정 파일 불러올 때의 처리 방법.

    auto configText = FileUtils::getInstance()->getStringFromFile(sourceFileName); // 설정 파일에서 스트링 불러오기.

    auto path = FileUtils::getInstance()->getWritablePath();   // 쓰기 가능한 경로 얻기
    
    FileUtils::getInstance()->writeStringToFile(configText, path + sourceFileName);  // 스트링을 쓰기 가능한 경로에 파일로 저장.
    if (FileUtils::getInstance()->isFileExist(path + sourceFileName) ) // 저장 됐는지 확인.
    {
        log("FileSystem | [%s] exist",(path + sourceFileName).c_str() );
    }
    else
    {
        log("FileSystem | %s not exist",(path + sourceFileName).c_str() );
    }

    m_fullSourceFileName = path + sourceName; // 저장된 파일 경로 저장.

위의 과정 적용 후, 설정 파일에 접근할 수 있다.

사용 예

ConfigINI::getInstance()->init(m_fullSourceFileName);
ConfigINI::getInstance()->getString("USER_MONEY");

댓글