やりたいこと
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);