Skip to content

Commit

Permalink
Merge branch 'v2.0-release' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	cocos2d/core/renderer/render-engine.js
  • Loading branch information
jareguo committed Aug 14, 2018
2 parents 20d5a38 + 3812bef commit 426f809
Show file tree
Hide file tree
Showing 51 changed files with 919 additions and 589 deletions.
14 changes: 14 additions & 0 deletions cocos2d/audio/CCAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ Audio.State = {
self._onLoaded();
}
});
cc.loader.load({
url: clip.nativeUrl,
// For audio, we should skip loader otherwise it will load a new audioClip.
skips: ['Loader'],
},
function (err, audioNativeAsset) {
if (err) {
cc.error(err);
return;
}
if (!clip.loaded) {
clip._nativeAsset = audioNativeAsset;
}
});
}
}
else {
Expand Down
7 changes: 4 additions & 3 deletions cocos2d/core/CCGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require('../audio/CCAudioEngine');
const debug = require('./CCDebug');
const renderer = require('./renderer/index.js');
const inputManager = CC_QQPLAY ? require('./platform/BKInputManager') : require('./platform/CCInputManager');
const dynamicAtlasManager = require('../core/renderer/utils/dynamic-atlas/manager');

/**
* @module cc
Expand Down Expand Up @@ -728,15 +729,15 @@ var game = {
'antialias': cc.macro.ENABLE_WEBGL_ANTIALIAS,
'alpha': cc.macro.ENABLE_TRANSPARENT_CANVAS
};
if (isWeChatGame) {
if (isWeChatGame || isQQPlay) {
opts['preserveDrawingBuffer'] = true;
}
renderer.initWebGL(localCanvas, opts);
this._renderContext = renderer.device._gl;

// Enable dynamic atlas manager by default
if (!cc.macro.CLEANUP_IMAGE_CACHE) {
cc.dynamicAtlasManager.enabled = true;
if (!cc.macro.CLEANUP_IMAGE_CACHE && dynamicAtlasManager) {
dynamicAtlasManager.enabled = true;
}
}
if (!this._renderContext) {
Expand Down
12 changes: 6 additions & 6 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ var Node = cc.Class({
* !#zh 返回这个将节点(局部)的空间坐标系转换成父节点的空间坐标系的矩阵。这个矩阵以像素为单位。
* @method getNodeToParentTransform
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand Down Expand Up @@ -2670,7 +2670,7 @@ var Node = cc.Class({
* 该方法基于节点坐标。
* @method getNodeToParentTransformAR
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand All @@ -2689,7 +2689,7 @@ var Node = cc.Class({
* !#zh 返回节点到世界坐标系的仿射变换矩阵。矩阵单位是像素。
* @method getNodeToWorldTransform
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand Down Expand Up @@ -2720,7 +2720,7 @@ var Node = cc.Class({
* 该方法基于节点坐标。
* @method getNodeToWorldTransformAR
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand All @@ -2743,7 +2743,7 @@ var Node = cc.Class({
* 该矩阵以像素为单位。返回的矩阵是只读的,不能更改。
* @method getParentToNodeTransform
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand All @@ -2763,7 +2763,7 @@ var Node = cc.Class({
* !#en 返回世界坐标系到节点坐标系的逆矩阵。
* @method getWorldToNodeTransform
* @deprecated since v2.0
* @param {AffineTransform} out The affine transform object to be filled with data
* @param {AffineTransform} [out] The affine transform object to be filled with data
* @return {AffineTransform} Same as the out affine transform object
* @example
* let affineTransform = cc.AffineTransform.create();
Expand Down
3 changes: 3 additions & 0 deletions cocos2d/core/components/CCAudioSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ var AudioSource = cc.Class({
* !#en Get current time
* !#zh 获取当前的播放时间
* @method getCurrentTime
* @return {Number}
*/
getCurrentTime: function () {
return this.audio.getCurrentTime();
Expand All @@ -317,6 +318,7 @@ var AudioSource = cc.Class({
* !#zh 设置当前的播放时间
* @method setCurrentTime
* @param {Number} time
* @return {Number}
*/
setCurrentTime: function (time) {
this.audio.setCurrentTime(time);
Expand All @@ -327,6 +329,7 @@ var AudioSource = cc.Class({
* !#en Get audio duration
* !#zh 获取当前音频的长度
* @method getDuration
* @return {Number}
*/
getDuration: function () {
return this.audio.getDuration();
Expand Down
4 changes: 4 additions & 0 deletions cocos2d/core/components/CCLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ let Label = cc.Class({
if (!this.font && !this._isSystemFontUsed) {
this.useSystemFont = true;
}
// Reapply default font family if necessary
if (this.useSystemFont && !this.fontFamily) {
this.fontFamily = 'Arial';
}

// Keep track of Node size
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateRenderData, this);
Expand Down
7 changes: 5 additions & 2 deletions cocos2d/core/components/CCRichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ let RichText = cc.Class({
},

_resetState () {
for (let i = this.node.children.length - 1; i >= 0; i--) {
let child = this.node.children[i];
let children = this.node.children;
for (let i = children.length - 1; i >= 0; i--) {
let child = children[i];
if (child.name === RichTextChildName) {
child.parent = null;
pool.put(child);
Expand All @@ -401,6 +402,8 @@ let RichText = cc.Class({
child.parent = null;
}
}
// HACK: Tolerate null parent child (upgrade issue may cause this special case)
children.length = 0;

this._labelSegments.length = 0;
this._labelSegmentsCache.length = 0;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/components/CCSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var Direction = cc.Enum({
*/
var Slider = cc.Class({
name: 'cc.Slider',
extends: require('./CCComponent'),
extends: Component,

editor: CC_EDITOR && {
menu: 'i18n:MAIN_MENU.component.ui/Slider',
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/components/CCSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ var Sprite = cc.Class({
}

this._updateAssembler();
this._renderData.uvDirty = true;
this.markForUpdateRenderData(true);

this.node.on(NodeEvent.SIZE_CHANGED, this._onNodeSizeDirty, this);
this.node.on(NodeEvent.ANCHOR_CHANGED, this._onNodeSizeDirty, this);
Expand Down
134 changes: 134 additions & 0 deletions cocos2d/core/components/WXSubContextView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

const Component = require('./CCComponent');

let WXSubContextView;

if (!CC_EDITOR && !CC_WECHATGAME) {
WXSubContextView = cc.Class({
name: 'cc.WXSubContextView',
extends: Component,
})
}
else {
/**
* !#en WXSubContextView is a view component which controls open data context viewport in Wechat game platform.<br/>
* The component's node size decide the viewport of the sub context content in main context,
* the entire sub context texture will be scaled to the node's bounding box area.<br/>
* This component provides multiple important features:<br/>
* 1. Sub context could use its own resolution size and policy.<br/>
* 2. Sub context could be minized to smallest size it needed.<br/>
* 3. Resolution of sub context content could be increased.<br/>
* 4. User touch input is transformed to the correct viewport.<br/>
* 5. Texture update is handled by this component. User don't need to worry.<br/>
* One important thing to be noted, whenever the node's bounding box change,
* you need to manually reset the viewport of sub context using updateSubContextViewport.
* !#zh WXSubContextView 可以用来控制微信小游戏平台开放数据域在主域中的视窗的位置。<br/>
* 这个组件的节点尺寸决定了开放数据域内容在主域中的尺寸,整个开放数据域会被缩放到节点的包围盒范围内。<br/>
* 在这个组件的控制下,用户可以更自由得控制开放数据域:<br/>
* 1. 子域中可以使用独立的设计分辨率和适配模式<br/>
* 2. 子域区域尺寸可以缩小到只容纳内容即可<br/>
* 3. 子域的分辨率也可以被放大,以便获得更清晰的显示效果<br/>
* 4. 用户输入坐标会被自动转换到正确的子域视窗中<br/>
* 5. 子域内容贴图的更新由组件负责,用户不需要处理<br/>
* 唯一需要注意的是,当子域节点的包围盒发生改变时,开发者需要使用 `updateSubContextViewport` 来手动更新子域视窗。
* @class WXSubContextView
* @extends Component
*/
WXSubContextView = cc.Class({
name: 'cc.WXSubContextView',
extends: Component,

editor: CC_EDITOR && {
menu: 'i18n:MAIN_MENU.component.others/WXSubContextView',
help: 'i18n:COMPONENT.help_url.wxSubContextView'
},

ctor () {
this._sprite = null;
this._tex = new cc.Texture2D();
this._context = null;
},

onLoad () {
// Setup subcontext canvas size
if (wx.getOpenDataContext) {
this._context = wx.getOpenDataContext();
let sharedCanvas = this._context.canvas;
if (sharedCanvas) {
sharedCanvas.width = this.node.width;
sharedCanvas.height = this.node.height;
}
this._tex.initWithElement(sharedCanvas);

this._sprite = this.node.getComponent(cc.Sprite);
if (!this._sprite) {
this._sprite = this.node.addComponent(cc.Sprite);
}
this._sprite.spriteFrame = new cc.SpriteFrame(this._tex);
}
else {
this.enabled = false;
}
},

onEnable () {
this.updateSubContextViewport();
},

update () {
if (!this._tex || !this._context) {
return;
}
this._tex.initWithElement(this._context.canvas);
this._sprite._activateMaterial();
},

/**
* !#en Update the sub context viewport manually, it should be called whenever the node's bounding box changes.
* !#zh 更新开放数据域相对于主域的 viewport,这个函数应该在节点包围盒改变时手动调用。
* @method updateSubContextViewport
*/
updateSubContextViewport () {
if (this._context) {
let box = this.node.getBoundingBoxToWorld();
let sx = cc.view._scaleX;
let sy = cc.view._scaleY;
this._context.postMessage({
fromEngine: true,
event: 'viewport',
x: box.x * sx + cc.view._viewportRect.x,
y: box.y * sy + cc.view._viewportRect.y,
width: box.width * sx,
height: box.height * sy
});
}
}
});

}

cc.WXSubContextView = module.exports = WXSubContextView;
Loading

0 comments on commit 426f809

Please sign in to comment.