0

Hi I have a problem when I try to add a background to using cocos2d. I followed the tutorial Denvycom doing a puzzle but with landscape orientation.

http://denvycom.com/blog/step-by-step-guide-on-how-to-build-your-first-slider-puzzle-game-in-cocos2d-for-android-part-1/

I try to make a game with portrait orientation does not work.

My code:

MainActivity.java

protected CCGLSurfaceView _glSurfaceView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    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);
    _glSurfaceView = new CCGLSurfaceView(this);
    setContentView(_glSurfaceView);


    CCDirector director = CCDirector.sharedDirector();
    director.attachInView(_glSurfaceView);
    director.setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait); // set orientation      

    CCScene scene = GameLayer.scene(); //
    CCDirector.sharedDirector().runWithScene(scene); 
}//fin oncreate

GameLayer.java

public class GameLayer extends CCLayer{

private static CGSize screenSize;
float generalscalefactor = 0.0f ; 

public GameLayer () {
    screenSize = CCDirector.sharedDirector().winSize();


    generalscalefactor  = CCDirector.sharedDirector().winSize().height / 500 ; 
    CCSprite background = CCSprite.sprite("bggreen.jpg");
    background.setScale(screenSize.width / background.getContentSize().width);      
    background.setAnchorPoint(CGPoint.ccp(0f,0f)) ;
    background.setPosition(CGPoint.ccp(0,0));
    addChild(background);
}


public static CCScene scene()
{
    CCScene scene = CCScene.node();
    CCLayer layer = new GameLayer();
    scene.addChild(layer);
    return scene;
}

}

Can you help me? Thank you very much in advance.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Garmael
  • 422
  • 3
  • 7
  • 19

2 Answers2

0

Have you checked if your AndroidManifest.xml file has this line in your activity tag?

android:screenOrientation="portrait"
alienchow
  • 383
  • 2
  • 7
  • Thanks for the contribution. But this is no problem. The application only runs on portratit by 'director.setDeviceOrientation (CCDirector.kCCDeviceOrientationPortrait);' – Garmael Dec 10 '14 at 19:24
0

The answer you can find it here

Black Screen on Android Launch Unless using Landscape Orientation

The problem came from the api version of the phone.

Community
  • 1
  • 1
Garmael
  • 422
  • 3
  • 7
  • 19