在Android上推出黑色屏幕除非使用横向横向、屏幕、黑色、Android

2023-09-07 14:32:37 作者:等你爱我丶

使用的Nexus 5(以及任何后来的Andr​​oid系统手机,如银河S5等),我的游戏,previously上的其它设备工作正常,只是表明推出时,该按钮可点击黑屏(即使你看不到它们)和SFX播放。

已经挣扎大规模这个问题,我总算将其固定在一定程度上,这是code的事项有关的推出;

  mGLSurfaceView =新CCGLSurfaceView(本);
        CCDirector.sharedDirector()。setScreenSize(CCDirector.sharedDirector()。使用winsize(),宽度,
                。CCDirector.sharedDirector()使用winsize()高度)。
        。CCDirector.sharedDirector()setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
        。CCDirector.sharedDirector()getActivity()的setContentView(mGLSurfaceView,createLayoutParams())。
        InitParam();
 

通过以​​下code以上,显示了启动黑屏(闪屏图形确实显示出,但主gameactivity屏不)。

然而,通过改变这一行;

CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);

CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft); 如何让android menu横向显示

这个应用程序显示 - 尽管伸出的图形和不理想!因此,这似乎是一个解决问题的原因是较新的Andr​​oid设备。 有搜查我能找到的code与gluPerspective片段,但我没有,在我的code改变。

Nexus的/银河拥有分辨率高达1920我相信,这样莫名其妙地需要找到一种方法来设置与现有的code工作。

另外code这可能有助于从TitleLayer

 公共TitleLayer()
    {
        超();
        CCSprite精灵= CCSprite.sprite(G._getImg(背景));
        G.setScale(精灵);
        sprite.setAnchorPoint(0,0);
        sprite.setPosition(0,0);
        的addChild(精灵);
        isTouchEnabled_ = TRUE;

    }
    公共静态无效setScale(){
        。G._scaleX = CCDirector.sharedDirector()使用winsize()宽/ G.WIN_W;
        G._scaleY = CCDirector.sharedDirector()使用winsize()高度/ G.WIN_H。;
    }
 

和它从这里得到的数值;

 公共静态活动g_Context;

    公共静态最终浮动DEFAULT_W = 360F;
    公共静态最终浮动DEFAULT_H = 480F;
    公共静态最终浮动WIN_W = 720F;
    公共静态最终浮动WIN_H = 1280F;



公共静态无效的getScale(){
        _scaleX = CCDirector.sharedDirector()使用winsize()宽/ WIN_W。;
        _scaleY = CCDirector.sharedDirector()使用winsize()高度/ WIN_H。;
    }
    公共静态浮动_getX(浮X){
        返回_scaleX * X;
    }

    公共静态浮动_getY(浮点Y){
        返回_scaleY * Y;
    }

公共静态无效setScale(的CCNode节点){
    node.setScaleX(_scaleX);
    node.setScaleY(_scaleY);
}

公共静态无效setScale(的CCNode节点,浮动比例因子){
    node.setScaleX(_scaleX *比例因子);
    node.setScaleY(_scaleY *比例因子);
}


公共静态无效setScale(的CCNode节点,布尔bSmall){
    浮规模= bSmall?
        (_scaleX< _scaleY _scaleX:_scaleY):
        (_scaleX> _scaleY _scaleX:_scaleY);
    node.setScale(规模);
}
 

解决方案

这是为Android 4.3及以上的问题提出,并在GitHub上论坛回答

虽然现在有很多工作周围像把低于code中的OnStart()方法。

  app.metric = 1;
CGSize S = CCDirector.sharedDirector()使用winsize()。
如果(s.height> 1280){
    app.metric = s.height / 1280;
    s.height = s.height / app.metric;
    s.width = s.width / app.metric;
    CCDirector.sharedDirector()setScreenSize((INT)s.width,(INT)s.height)。
}
 

或者如果你有cocos2d的源$ C ​​$ C,那么改变下面提到行了。

 公共静态最终诠释kCCDirectorProjectionDefault = kCCDirectorProjection3D;
 

也可以实现这个解决方案

在CCDirector的setProjection方法 - 更改gluPerspective到2000年,而不是1500 新生产线将是这样的 - GLU.gluPerspective(GL,60,size.width / size.height,0.5F,2000.0f);

但是,这一切都是变通的问题,所以如果你真的想好解决方案,那么你可以得到最新的cocos2d的罐子或源$ C ​​$ c和在应用程序中实现。

Using a Nexus 5 (and any of the later android handsets such as Galaxy S5 etc) my game which previously worked fine on other devices, simply shows a black screen when launched, the buttons can be clicked (even though you cannot see them) and the sfx plays.

Having struggled massively with this problem, I somehow managed to fix it to some degree this is the code that matters regarding the launch;

mGLSurfaceView = new CCGLSurfaceView(this);        
        CCDirector.sharedDirector().setScreenSize(CCDirector.sharedDirector().winSize().width, 
                CCDirector.sharedDirector().winSize().height);
        CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
        CCDirector.sharedDirector().getActivity().setContentView(mGLSurfaceView, createLayoutParams());
        InitParam();

With the following code above, shows a black screen on launch (the splash screen graphic DOES show but the main gameactivity screen does not).

However, by changing this line;

CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);

to

CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft);

The app displays - albeit stretched out graphics and not ideal! So this seems to be a resolution issue due to the newer android devices. Having searched I could find snippets of code relating to 'gluPerspective' but I do not have that in my code to change.

The Nexus / Galaxy has resolutions up to 1920 I believe, so somehow need to find a way to set that to work with the existing code.

Additional code which may help, from the TitleLayer

public TitleLayer()
    {
        super();        
        CCSprite sprite = CCSprite.sprite(G._getImg("background"));
        G.setScale(sprite);
        sprite.setAnchorPoint(0, 0);
        sprite.setPosition(0, 0);
        addChild(sprite);
        isTouchEnabled_= true;

    }
    public static void setScale(){
        G._scaleX = CCDirector.sharedDirector().winSize().width / G.WIN_W; 
        G._scaleY = CCDirector.sharedDirector().winSize().height / G.WIN_H;
    }

And it gets the values from here;

public static Activity      g_Context; 

    public static final float       DEFAULT_W       = 360f;
    public static final float       DEFAULT_H       = 480f;
    public static final float       WIN_W           = 720f; 
    public static final float       WIN_H           = 1280f;



public static void getScale(){          
        _scaleX = CCDirector.sharedDirector().winSize().width / WIN_W;
        _scaleY =  CCDirector.sharedDirector().winSize().height / WIN_H;        
    }
    public static float _getX(float x) {
        return _scaleX * x;
    }

    public static float _getY(float y) {
        return _scaleY * y;
    }

public static void setScale(CCNode node) {
    node.setScaleX(_scaleX);
    node.setScaleY(_scaleY);
}

public static void setScale(CCNode node, float scaleFactor) {
    node.setScaleX(_scaleX*scaleFactor);
    node.setScaleY(_scaleY*scaleFactor);
}


public static void setScale(CCNode node, boolean bSmall) {
    float scale = bSmall ?
        (_scaleX<_scaleY ? _scaleX : _scaleY) :
        (_scaleX>_scaleY ? _scaleX : _scaleY);
    node.setScale(scale);
}

解决方案

This is a issue of cocos2d for Android 4.3 and above Issue raised and answered at github forum

Though there are many work around like putting the below code in onStart() method.

app.metric = 1;
CGSize s = CCDirector.sharedDirector().winSize();
if (s.height > 1280) {
    app.metric = s.height / 1280;
    s.height = s.height / app.metric;
    s.width = s.width / app.metric;
    CCDirector.sharedDirector().setScreenSize((int) s.width, (int) s.height);
}

or if you have the source code of cocos2d then change the line mentioned below.

public static final int kCCDirectorProjectionDefault = kCCDirectorProjection3D;

or you can implement this solution

In CCDirector's setProjection Method - Change gluPerspective to 2000 instead of 1500 New Line will be like this - GLU.gluPerspective(gl, 60, size.width/size.height, 0.5f, 2000.0f);

But all this are work around for the issue, so if you really want good solution then you can get the latest cocos2d jar or source code and implement in your app.