LoginSignup
0
0

More than 5 years have passed since last update.

cocos2d-js(v3.x)で背景を透明にする方法(HTML5版のみ)

Posted at

やりたいこと

cocos2d-jsでブラウザ向けゲームのリリース等でcocos2d-jsの背景を透過させたい
(cocos2dよりも後ろに、それ以外の描画結果を合成表示したい場合など)

CCBoot.js の変更

[project]/frameworks/cocos2d-html5/ にある
CCBoot.jsの'alpha':falseを'alpha:true'に書き換える。

【変更前】

CCBoot.js
        if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
            this._renderContext = cc._renderContext = cc.webglContext
             = cc.create3DContext(localCanvas, {
                'stencil': true,
                'alpha': false
            });
        }

【変更後】

CCBoot.js
        if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
            this._renderContext = cc._renderContext = cc.webglContext
             = cc.create3DContext(localCanvas, {
                'stencil': true,
                'alpha': true
            });
        }

背景描画色を透過率α(アルファ)=0 で指定する

main.js等で以下のように背景描画色を透明にする

main.js
   cc.LoaderScene.preload(g_resources, function () {   

        //背景描画色を透明に
        cc.director.setClearColor(cc.color(0, 0, 0, 0));

        cc.director.runScene(new GameScene());
    }, this);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0