当我尝试添加背景以使用cocos2d时,我遇到了问题。 我按照教程Denvycom做了一个拼图,但是横向了。
我尝试制作纵向游戏不起作用。
我的代码:
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;
}
}
你能帮帮我吗?
非常感谢你提前。
答案 0 :(得分:0)
您是否检查过AndroidManifest.xml文件是否在您的活动代码中包含此行?
android:screenOrientation="portrait"
答案 1 :(得分:0)