显示礼物

直播技术之使用cocos2dx显示礼物

1.需要使用到cocos2dx显示礼物则需要继承Cocos2dxActivity
首次先Cocos2dxActivity->onCreate()->init()

    public void init() {

        // FrameLayout
        ViewGroup.LayoutParams framelayout_params =
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                       ViewGroup.LayoutParams.MATCH_PARENT);
        mFrameLayout = new FrameLayout(this);
        mFrameLayout.setLayoutParams(framelayout_params);

        // Cocos2dxEditText layout
        //ViewGroup.LayoutParams edittext_layout_params =
        //    new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
        //                               ViewGroup.LayoutParams.WRAP_CONTENT);
        //Cocos2dxEditText edittext = new Cocos2dxEditText(this);
        //edittext.setLayoutParams(edittext_layout_params);

        // ...add to FrameLayout
        //mFrameLayout.addView(edittext);

        // Cocos2dxGLSurfaceView
        this.mGLSurfaceView = this.onCreateView();

        // ...add to FrameLayout
        mFrameLayout.addView(this.mGLSurfaceView);

        // Switch to supported OpenGL (ARGB888) mode on emulator
        if (isAndroidEmulator())
           this.mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

        this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
        //this.mGLSurfaceView.setCocos2dxEditText(edittext);

        // Set framelayout as the content view
        setContentView(mFrameLayout);
    }

其实Cocos2dxActivity已经给我我们提示,需要将我们自定义的布局按照怎样的顺序添加到ContentView中(10-18行);

abstract public View createCustomView();

mFrameLayout.addView(createCustomView(), new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

所以只用在createCustomView()中实现自己的布局就可以。

2.使用自定义GLSurfaceView与GLSurfaceView.Renderer播放视频

    render = new SurfaceView.Renderer(context);
    render.setGlSurfaceView(this);
    setEGLContextClientVersion(2);    // 设置opengl es2 版本
    this.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setRenderer(render);        // 设置渲染
    setRenderMode(RENDERMODE_WHEN_DIRTY);        // 需要时渲
    setZOrderOnTop(false);//重点,小心坑;在Cocos2dxActivity->onCreateView()->glSurfaceView.setZOrderOnTop(true);所以这里设置强制为false,是自定义GLSurfaceView在动画的下面

    //Cocos2dxActivity->onCreateView()
    public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
        //this line is need on some device if we specify an alpha bits
        if(this.mGLContextAttrs[3] > 0) glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        glSurfaceView.setZOrderOnTop(true);//

        Cocos2dxEGLConfigChooser chooser = new Cocos2dxEGLConfigChooser(this.mGLContextAttrs);
        glSurfaceView.setEGLConfigChooser(chooser);

        return glSurfaceView;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值