【问题标题】:Cocos2d Android Add background in portrait orientationCocos2d Android 纵向添加背景
【发布时间】:2014-12-10 09:17:20
【问题描述】:

您好,我在尝试添加背景以使用 cocos2d 时遇到问题。 我按照教程 Denvycom 做了一个拼图,但是是横向的。

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

我尝试制作一个纵向的游戏不起作用。

我的代码:

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;
}

}

你能帮帮我吗? 非常感谢您。

【问题讨论】:

    标签: java android background cocos2d-android


    【解决方案1】:

    您是否检查过您的 AndroidManifest.xml 文件在您的活动标签中是否有这一行?

    android:screenOrientation="portrait"
    

    【讨论】:

    • 感谢您的贡献。但这没有问题。该应用程序仅通过 'director.setDeviceOrientation (CCDirector.kCCDeviceOrientationPortrait);' 在 portratit 上运行
    【解决方案2】:

    你可以在这里找到答案

    Black Screen on Android Launch Unless using Landscape Orientation

    问题来自手机的api版本。

    【讨论】:

      猜你喜欢
      • 2013-03-01
      • 2010-12-29
      • 1970-01-01
      • 2011-04-24
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      相关资源
      最近更新 更多