Saturday, November 22, 2014

Clear Application Data with ADB at the command line

You can use package manager (pm) to clear data for installed apps (same as pressing the 'clear data' button in the app settings on your device).

Run this adb command, replacing 'com.company.games.game' with your package name from AndroidManfiest.xml

adb shell pm clear com.company.games.game

This method depends on the 'pm' tool being resident on the Android device, which is not always the case.

Thursday, November 20, 2014

Cocos2d-x v2.2 Fullscreen Linux Support

Add this method to CCEGLView.cpp and CCEGLView.h

void CCEGLView::setFrameSize(float width, float height, bool fullscreen)
{
bool eResult = false;
int u32GLFWFlags = GLFW_WINDOW;
if(fullscreen) {
u32GLFWFlags = GLFW_FULLSCREEN;
}
//create the window by glfw.
//check
CCAssert(width!=0&&height!=0, "invalid window's size equal 0");
//Inits GLFW
eResult = glfwInit() != GL_FALSE;
if (!eResult) {
CCAssert(0, "fail to init the glfw");
}
if(fullscreen) {
GLFWvidmode desktopMode;
glfwGetDesktopMode(&desktopMode);
CCLog("W: %d", (int)desktopMode.Width);
CCLog("H: %d", (int)desktopMode.Height);
height = (int)desktopMode.Height;
width = (int)desktopMode.Width;
}
/* Updates window hint */
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
int iDepth = 16; // set default value
/* Depending on video depth */
switch(iDepth)
{
/* 16-bit */
case 16:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 5, 6, 5, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false;
break;
}
/* 24-bit */
case 24:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 8, 8, 8, 0, 16, 8, (int)u32GLFWFlags) != false) ? true : false;
break;
}
/* 32-bit */
default:
case 32:
{
/* Updates video mode */
eResult = (glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 8, (int)u32GLFWFlags) != GL_FALSE) ? true :false;
break;
}
}
/* Success? */
if(eResult)
{
glfwSetWindowSize(width, height);
// Move window to the upper left corner.
glfwSetWindowPos(0, 0);
glfwEnable(GLFW_MOUSE_CURSOR);
/* Updates actual size */
// glfwGetWindowSize(&width, &height);
CCEGLViewProtocol::setFrameSize(width, height);
/* Updates its title */
glfwSetWindowTitle("Cocos2dx-Linux");
//set the init flag
bIsInit = true;
//register the glfw key event
glfwSetKeyCallback(keyEventHandle);
//register the glfw char event
glfwSetCharCallback(charEventHandle);
//register the glfw mouse event
glfwSetMouseButtonCallback(mouseButtonEventHandle);
//register the glfw mouse pos event
glfwSetMousePosCallback(mousePosEventHandle);
//register the glfw keyboard event
glfwSetKeyCallback(keyboardEventHandle);
glfwSetWindowCloseCallback(closeEventHandle);


//Inits extensions
eResult = initExtensions();
if (!eResult) {
CCAssert(0, "fail to init the extensions of opengl");
}
initGL();
}
}

Tuesday, November 04, 2014

Android Lollipop Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)

Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)


  Index: Cocos2dxMusic.java
  ===================================================================
  --- Cocos2dxMusic.java (revision 21981)
  +++ Cocos2dxMusic.java (working copy)
  @@ -110,12 +110,12 @@
        Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic: background media player is null");
      } else {
        // if the music is playing or paused, stop it
  - this.mBackgroundMediaPlayer.stop();
  + //this.mBackgroundMediaPlayer.pause();
   
        this.mBackgroundMediaPlayer.setLooping(isLoop);
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + //this.mBackgroundMediaPlayer.prepare();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();
   
  @@ -129,6 +129,9 @@
    public void stopBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
        this.mBackgroundMediaPlayer.stop();
  + this.mBackgroundMediaPlayer.release();
  + this.mBackgroundMediaPlayer = null;
  + this.mCurrentPath = null;
   
        // should set the state, if not, the following sequence will be error
        // play -> pause -> stop -> resume
  @@ -152,10 +155,9 @@
   
    public void rewindBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
  - this.mBackgroundMediaPlayer.stop();
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + this.mBackgroundMediaPlayer.pause();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();