Skip to content

startGameByDirectoryPath ​

Start a Game (by Local Directory Path) ​

startGameByDirectoryPath is one of the most low-level launch interfaces. It directly loads an already-extracted game directory. Because this interface completely skips the download and extraction stages, it can enter the initialization flow with very low I/O overhead.

This interface is commonly used for developer mode, resource pre-placement in the Assets directory with manual extraction, or scenarios where the business side has a highly customized resource distribution system.


Method Declaration ​

java
/**
 * Start a game by local game directory path
 *
 * @param directoryPath     Local directory path
 * @param params            Parameter object
 * @param listener          Launch process listener
 * @return SUDOPGameTask    Task handle
 */
public static SUDOPGameTask startGameByDirectoryPath(String directoryPath, SUDOPGamePackageParams params, SUDOPStartGameListener listener);

Parameters ​

FieldTypeDescription
directoryPathStringRequired. The absolute path of the game resource folder. The root of the directory must contain app.json.

1. SUDOPStartGameListener ​

  • void onGamePkgDecrypt(GamePkgDecryptHandle handle, String filePath): Game package decryption callback.
  • void onCreated(SUDRTGameHandle gameHandle, SUDOPGameInfo gameInfo): The game instance has been created. gameHandle is the game instance handle, which can be used to control the game lifecycle or interaction later.
  • void onSuccess(String gameId, SUDRTGameHandle gameHandle): The game started successfully.
  • void onFailure(int retCode, String retMsg): The game failed to start.

2. GamePkgDecryptHandle ​

  • void success(String decryptedFilePath, boolean isDeleteFile): Decryption succeeded. decryptedFilePath: the path of the decrypted file. isDeleteFile: whether to delete the file after the game finishes loading.

  • void fail(int retCode, String retMsg): Decryption failed. retCode: error code. retMsg: error message description.


Runtime Behavior ​

  1. Structure verification: The SDK checks whether the required entry files exist under the directoryPath directory.
  2. Zero-copy loading: The SDK runtime reads resources directly from this path and does not copy them to any other cache location.
  3. Engine startup: Loads the JS core library and starts the game's main logic.
  4. View mounting: Returns gameView in the onSuccess callback; the developer adds it to the Activity layout to see the screen.

Example Code ​

java
String directoryPath = getFilesDir().getAbsolutePath() + "/game_res/my_tetris_folder/";

SUDOPGamePackageParams params = new SUDOPGamePackageParams();
params.version = "gamePkgVersion";
params.fid = "2e7ca170f33629c7baf4dc430c541c43";
params.fidType = FIDType.MD5;
params.appGameID = "appGameID";
params.appCPID = "Game Developer id";
params.appGroupID = "Game developer group id";

SUDOPGameTask gameTask = SUDOP.startGameByDirectoryPath(directoryPath, params, new SUDOPStartGameListener() {
    @Override
    public void onGameViewCreated(View view) {
        // Attach view to the host layout here.
    }

    @Override
    public void onProgress(int progress) {
        // Update loading progress (0–100).
    }

    @Override
    public void onGamePkgDecrypt(GamePkgDecryptHandle handle, String filePath) {
    }
    @Override
    public void onCreated(SUDRTGameHandle gameHandle, SUDOPGameInfo gameInfo) {
    }
    @Override
    public void onSuccess(String gameId, SUDRTGameHandle gameHandle) {
        // Simply attach this View to your app's own page
        View gameView = gameHandle.getGameView();
    }
    @Override
    public void onFailure(int retCode, String retMsg) {
    }
});

Notes ​

  • Path convention: Make sure you pass a folder path. If files in this directory change, you may need to call the launch interface again to ensure the logic is correct.
  • Resource management: The SDK does not automatically clean up the directory specified by this interface. The business side is responsible for the lifecycle management of this directory (such as updating or deleting old directories).
  • Thread safety: The callbacks execute on the main thread, so you can operate the UI directly.

Also implement onGameViewCreated(View view) to attach the game view and onProgress(int progress) for progress from 0 to 100. The gameInfo argument of onCreated is the SUDOPGameInfo game information.