From b1c84ac0d4ad46737fb1379980e794538dd25d72 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 20 Apr 2018 11:57:46 +0800 Subject: [PATCH] Fix global canvas undefined issue in JSB --- cocos2d/core/CCGame.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 085ed5164a..cfc7fbae51 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -701,10 +701,13 @@ var game = { if (cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB) { localCanvas = wx.getSharedCanvas(); } + else if (JSB) { + localCanvas = window.__cccanvas; + } else { localCanvas = canvas; } - this.canvas = cc._canvas = localCanvas; + this.canvas = localCanvas; } else if (isQQPlay) { this.container = cc.container = document.createElement("DIV");