2013-07-18 55 views
0

完整的代碼後,打開科科斯2D項目在這裏我的問題是:Android的屏幕變黑,如果我得到了一個活動

  1. 我運行它運行正常
  2. 我按後退按鈕的代碼
  3. 我重新從移動
  4. 屏幕應用變黑

我已經測試在Android V2.3這個代碼(薑餅)OS

這是問題,因爲茯苓2D庫的,請讓我知道在此先感謝...

import org.cocos2d.layers.CCColorLayer; 
    import org.cocos2d.layers.CCLayer; 
    import org.cocos2d.layers.CCScene; 
    import org.cocos2d.nodes.CCDirector; 
    import org.cocos2d.nodes.CCSprite; 
    import org.cocos2d.opengl.CCGLSurfaceView; 
    import org.cocos2d.types.CGPoint; 
    import org.cocos2d.types.CGSize; 
    import org.cocos2d.types.ccColor4B; 

    import android.app.Activity; 
    import android.os.Bundle; 
    import android.util.Log; 
    import android.view.Window; 
    import android.view.WindowManager; 

    public class GameActivity extends Activity { 
     private CCGLSurfaceView mGLSurfaceView; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

    //  Log.d("hii", "m here on create"); 

      // set the window status, no tile, full screen and don't sleep 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 
        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

      mGLSurfaceView = new CCGLSurfaceView(this); 

      setContentView(mGLSurfaceView); 

      // attach the OpenGL view to a window 
      CCDirector.sharedDirector().attachInView(mGLSurfaceView); 

      // no effect here because device orientation is controlled by manifest 
      CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait); 

      // show FPS 
      // set false to disable FPS display, but don't delete fps_images.png!! 
      CCDirector.sharedDirector().setDisplayFPS(false); 

      // frames per second 
      CCDirector.sharedDirector().setAnimationInterval(1.0f/60); 
      CCScene scene = TemplateLayer.scene(); 

      // Make the Scene active 
      CCDirector.sharedDirector().runWithScene(scene); 
     } 

     @Override 
     public void onStart() { 
      super.onStart();  
      Log.d("hii", "m here on start"); 
     } 

     @Override 
     public void onPause() { 
      super.onPause(); 
      Log.d("hii", "m here on pause"); 
      CCDirector.sharedDirector().pause(); 
     } 

     @Override 
     public void onResume() { 
      super.onResume(); 
      Log.d("hii", "m here on resumae"); 
      CCDirector.sharedDirector().resume(); 
     } 

     @Override 
     public void onDestroy() { 
      super.onDestroy(); 
      Log.d("hii", "m here on destroy"); 
      CCDirector.sharedDirector().end(); 
     } 

     public static class TemplateLayer extends CCColorLayer 
     { 


      CGSize winSize = CCDirector.sharedDirector().displaySize(); 

      //killing sprite 
      CCSprite killerchild,boat,pirates; 

      public static CCScene scene() 
      { 

       CCScene scene = CCScene.node(); 
       CCLayer layer = new TemplateLayer(ccColor4B.ccc4(0, 225, 145, 146)); 

       scene.addChild(layer); 

       return scene; 
      } 


       @Override 
       public void onEnter() { 

        // then iterate over all the children 
        super.onEnter(); 

       } 

       @Override 
       public void onExit() { 

        super.onExit(); 

       } 



      protected TemplateLayer(ccColor4B color) 
      { 

       super(color); 

       this.setIsTouchEnabled(true); 


       killerchild = CCSprite.sprite("logo.png"); 
       killerchild.setAnchorPoint(CGPoint.ccp(0, 0)); 

       killerchild.setPosition(CGPoint.ccp(winSize.width/2-killerchild.getContentSize().width/2, winSize.height-killerchild.getContentSize().height)); 
       addChild(killerchild); 

       boat = CCSprite.sprite("boat.png"); 
       boat.setAnchorPoint(CGPoint.ccp(0, 0)); 

       boat.setPosition(CGPoint.ccp(winSize.width/2-boat.getContentSize().width/2,-boat.getContentSize().height/4)); 
       addChild(boat); 


       pirates = CCSprite.sprite("Pirates.png"); 
       pirates.setAnchorPoint(CGPoint.ccp(0, 0)); 

       pirates.setPosition(CGPoint.ccp(winSize.width/2-pirates.getContentSize().width/2,winSize.height/2-pirates.getContentSize().height/2)); 
       addChild(pirates,-1); 

      } 

     } 

    } 
+0

代碼是正確的,但不知道會發生什麼與你..如果你在這裏複製TemplateLayer類代碼然後我會檢查什麼是這個問題?從頂部到你的templateLater構造器 –

+0

我還需要在此代碼中添加哪些內容 – shankey

+0

某些行可以在其中定義所有CCSprite等等...... –

回答

0

我認爲這是一個問題,因爲你使用的是Cocos 2D的jar文件。我用我的罐子,我沒有得到這個問題。請從下面的鏈接下載並檢查。

https://www.wetransfer.com/downloads/8d55297ac0f605408682fea530e0419120130920102338/e48fbd145e26dc5968402f3a8915678620130920102338/8f429f

請與此庫檢查,讓我知道,如果問題仍然存在。

+0

非常感謝ajit,對於遲到的回覆感到抱歉。它說下載不再可用,請你可以給更新的jar文件鏈接.... – shankey

0

在TemplateLayer類擴展CCColorLayer:

public static CCScene scene() { 
    CCScene scene = CCScene.node(); 
    CCLayer layer = new TemplateLayer(ccColor4B.ccc4(0, 225, 145, 146)); 
    scene.addChild(layer); 
    return scene; 
} 

並更改TemplateLayer()consturctor成:

TemplateLayer(ccColor4B color){ 
super(color); 
} 

運行項目

+0

同樣的問題,但現在屏幕已經從黑色轉換爲綠色。我正在使用samsang y進行測試 – shankey

+0

看來你的圖層上沒有任何東西。你必須添加一些精靈等等wtc –

+0

你到底想要什麼遊戲層? –

相關問題