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.
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.