Skip to content

Commit

Permalink
Fix user reported issues (cocos#3081)
Browse files Browse the repository at this point in the history
* Upgrade render engine to fix some issues

* preserve drawing buffer in qqplay

* Fix label issue when using system font and fontFamily is not set

* Secure Editbox _impl access

* Fix Joint.getReactionForce

* Remove cc.director.getProjection usage

* Fix particle system color type issue in editor

* Apply Skeleton frame when changing animation in editor

* Fix docs, improve deprecation
  • Loading branch information
pandamicro authored Aug 14, 2018
1 parent 18fbcbb commit 411e52b
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cocos2d/core/CCGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ 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);
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
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
33 changes: 25 additions & 8 deletions cocos2d/core/components/editbox/CCEditBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ let EditBox = cc.Class({
}

this._string = value;
this._updateString(value);
if (this._impl) {
this._updateString(value);
}
}
},

Expand Down Expand Up @@ -113,7 +115,9 @@ let EditBox = cc.Class({
displayName: 'KeyboardReturnType',
type: KeyboardReturnType,
notify () {
this._impl.returnType = this.returnType;
if (this._impl) {
this._impl.returnType = this.returnType;
}
}
},

Expand All @@ -128,7 +132,10 @@ let EditBox = cc.Class({
default: InputFlag.DEFAULT,
type: InputFlag,
notify () {
this._impl.inputFlag = this.inputFlag;
if (this._impl) {
this._impl.setInputFlag(this.inputFlag);
this._updateString(this._string);
}
}
},
/**
Expand All @@ -145,7 +152,9 @@ let EditBox = cc.Class({
default: InputMode.ANY,
type: InputMode,
notify () {
this._impl.setInputMode(this.inputMode);
if (this._impl) {
this._impl.setInputMode(this.inputMode);
}
}
},

Expand Down Expand Up @@ -206,7 +215,9 @@ let EditBox = cc.Class({
if (this._placeholderLabel) {
this._placeholderLabel.string = this.placeholder;
}
this._impl.setPlaceholderText(this.placeholder);
if (this._impl) {
this._impl.setPlaceholderText(this.placeholder);
}
}
},

Expand Down Expand Up @@ -254,7 +265,9 @@ let EditBox = cc.Class({
tooltip: CC_DEV && 'i18n:COMPONENT.editbox.max_length',
default: 20,
notify () {
this._impl.setMaxLength(this.maxLength);
if (this._impl) {
this._impl.setMaxLength(this.maxLength);
}
}
},

Expand All @@ -268,7 +281,9 @@ let EditBox = cc.Class({
tooltip: CC_DEV && 'i18n:COMPONENT.editbox.stay_on_top',
default: false,
notify () {
this._updateStayOnTop();
if (this._impl) {
this._updateStayOnTop();
}
}
},

Expand All @@ -286,7 +301,9 @@ let EditBox = cc.Class({
},
set (value) {
this._tabIndex = value;
this._impl.setTabIndex(value);
if (this._impl) {
this._impl.setTabIndex(value);
}
}
},

Expand Down
7 changes: 4 additions & 3 deletions cocos2d/core/physics/joint/CCJoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ var Joint = cc.Class({
* 获取关节的反作用力。
* @method getReactionForce
* @param {Number} timeStep - The time to calculate the reaction force for.
* @return {Number}
* @return {Vec2}
*/
getReactionForce: function (timeStep) {
var out = cc.v2();
if (this._joint) {
return this._joint.GetReactionForce(timeStep);
return this._joint.GetReactionForce(timeStep, out);
}
return 0;
return out;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCInputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ let inputManager = {
},

/**
* @method getTouchByXY
* @method getMouseEvent
* @param {Vec2} location
* @param {Vec2} pos
* @param {Number} eventType
Expand Down
1 change: 0 additions & 1 deletion cocos2d/core/platform/CCView.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ cc.js.mixin(View.prototype, {
cc.game.frame.style.width = width + "px";
cc.game.frame.style.height = height + "px";
this._resizeEvent();
cc.director.setProjection(cc.director.getProjection());
},

/**
Expand Down
31 changes: 17 additions & 14 deletions cocos2d/core/renderer/render-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9497,9 +9497,9 @@ var Device = function Device(canvasEL, opts) {

try {
gl = canvasEL.getContext('webgl', opts)
|| canvasEL.getContext('experimental-webgl', opts)
|| canvasEL.getContext('webkit-3d', opts)
|| canvasEL.getContext('moz-webgl', opts);
|| canvasEL.getContext('experimental-webgl', opts)
|| canvasEL.getContext('webkit-3d', opts)
|| canvasEL.getContext('moz-webgl', opts);
} catch (err) {
console.error(err);
return;
Expand Down Expand Up @@ -9561,13 +9561,16 @@ Device.prototype._initExtensions = function _initExtensions (extensions) {
for (var i = 0; i < extensions.length; ++i) {
var name = extensions[i];

try {
var ext = gl.getExtension(name);
if (ext) {
this$1._extensions[name] = ext;
var vendorPrefixes = ["", "WEBKIT_", "MOZ_"];
for (var j = 0; j < vendorPrefixes.length; j++) {
try {
var ext = gl.getExtension(vendorPrefixes[j] + name);
if (ext) {
this$1._extensions[name] = ext;
}
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
}
};
Expand Down Expand Up @@ -12838,7 +12841,7 @@ var ProgramLib = function ProgramLib(device, templates, chunks) {
if ( chunks === void 0 ) chunks = {};

this._device = device;
this._precision = "precision mediump float;\n";
this._precision = "precision highp float;\n";

// register templates
this._templates = {};
Expand Down Expand Up @@ -13651,15 +13654,15 @@ var chunks = {
var templates = [
{
name: 'gray_sprite',
vert: '\n \nuniform mat4 viewProj;\nattribute vec3 a_position;\nattribute vec2 a_uv0;\nvarying vec2 uv0;\nvoid main () {\n vec4 pos = viewProj * vec4(a_position, 1);\n gl_Position = pos;\n uv0 = a_uv0;\n}',
frag: '\n \nuniform sampler2D texture;\nvarying vec2 uv0;\nuniform vec4 color;\nvoid main () {\n vec4 c = color * texture2D(texture, uv0);\n float gray = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;\n gl_FragColor = vec4(gray, gray, gray, c.a);\n}',
vert: '\n \nuniform mat4 viewProj;\nattribute vec3 a_position;\nattribute mediump vec2 a_uv0;\nvarying mediump vec2 uv0;\nvoid main () {\n vec4 pos = viewProj * vec4(a_position, 1);\n gl_Position = pos;\n uv0 = a_uv0;\n}',
frag: '\n \nuniform sampler2D texture;\nvarying mediump vec2 uv0;\nuniform lowp vec4 color;\nvoid main () {\n vec4 c = color * texture2D(texture, uv0);\n float gray = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;\n gl_FragColor = vec4(gray, gray, gray, c.a);\n}',
defines: [
],
},
{
name: 'sprite',
vert: '\n \nuniform mat4 viewProj;\n#ifdef use2DPos\nattribute vec2 a_position;\n#else\nattribute vec3 a_position;\n#endif\nattribute vec4 a_color;\n#ifdef useModel\n uniform mat4 model;\n#endif\n#ifdef useTexture\n attribute vec2 a_uv0;\n varying vec2 uv0;\n#endif\n#ifndef useColor\nvarying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n mat4 mvp;\n #ifdef useModel\n mvp = viewProj * model;\n #else\n mvp = viewProj;\n #endif\n #ifdef use2DPos\n vec4 pos = mvp * vec4(a_position, 0, 1);\n #else\n vec4 pos = mvp * vec4(a_position, 1);\n #endif\n #ifndef useColor\n v_fragmentColor = a_color;\n #endif\n #ifdef useTexture\n uv0 = a_uv0;\n #endif\n gl_Position = pos;\n}',
frag: '\n \n#ifdef useTexture\n uniform sampler2D texture;\n varying vec2 uv0;\n#endif\n#ifdef alphaTest\n uniform float alphaThreshold;\n#endif\n#ifdef useColor\n uniform vec4 color;\n#else\n varying vec4 v_fragmentColor;\n#endif\nvoid main () {\n #ifdef useColor\n vec4 o = color;\n #else\n vec4 o = v_fragmentColor;\n #endif\n #ifdef useTexture\n o *= texture2D(texture, uv0);\n #endif\n #ifdef alphaTest\n if (o.a <= alphaThreshold)\n discard;\n #endif\n gl_FragColor = o;\n}',
vert: '\n \nuniform mat4 viewProj;\n#ifdef use2DPos\nattribute vec2 a_position;\n#else\nattribute vec3 a_position;\n#endif\nattribute lowp vec4 a_color;\n#ifdef useModel\n uniform mat4 model;\n#endif\n#ifdef useTexture\n attribute mediump vec2 a_uv0;\n varying mediump vec2 uv0;\n#endif\n#ifndef useColor\nvarying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n mat4 mvp;\n #ifdef useModel\n mvp = viewProj * model;\n #else\n mvp = viewProj;\n #endif\n #ifdef use2DPos\n vec4 pos = mvp * vec4(a_position, 0, 1);\n #else\n vec4 pos = mvp * vec4(a_position, 1);\n #endif\n #ifndef useColor\n v_fragmentColor = a_color;\n #endif\n #ifdef useTexture\n uv0 = a_uv0;\n #endif\n gl_Position = pos;\n}',
frag: '\n \n#ifdef useTexture\n uniform sampler2D texture;\n varying mediump vec2 uv0;\n#endif\n#ifdef alphaTest\n uniform lowp float alphaThreshold;\n#endif\n#ifdef useColor\n uniform lowp vec4 color;\n#else\n varying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n #ifdef useColor\n vec4 o = color;\n #else\n vec4 o = v_fragmentColor;\n #endif\n #ifdef useTexture\n o *= texture2D(texture, uv0);\n #endif\n #ifdef alphaTest\n if (o.a <= alphaThreshold)\n discard;\n #endif\n gl_FragColor = o;\n}',
defines: [
{ name: 'useTexture', },
{ name: 'useModel', },
Expand Down
19 changes: 14 additions & 5 deletions cocos2d/core/renderer/render-engine.jsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,15 @@ var chunks = {
var templates = [
{
name: 'gray_sprite',
vert: '\n \nuniform mat4 viewProj;\nattribute vec3 a_position;\nattribute vec2 a_uv0;\nvarying vec2 uv0;\nvoid main () {\n vec4 pos = viewProj * vec4(a_position, 1);\n gl_Position = pos;\n uv0 = a_uv0;\n}',
frag: '\n \nuniform sampler2D texture;\nvarying vec2 uv0;\nuniform vec4 color;\nvoid main () {\n vec4 c = color * texture2D(texture, uv0);\n float gray = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;\n gl_FragColor = vec4(gray, gray, gray, c.a);\n}',
vert: '\n \nuniform mat4 viewProj;\nattribute vec3 a_position;\nattribute mediump vec2 a_uv0;\nvarying mediump vec2 uv0;\nvoid main () {\n vec4 pos = viewProj * vec4(a_position, 1);\n gl_Position = pos;\n uv0 = a_uv0;\n}',
frag: '\n \nuniform sampler2D texture;\nvarying mediump vec2 uv0;\nuniform lowp vec4 color;\nvoid main () {\n vec4 c = color * texture2D(texture, uv0);\n float gray = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;\n gl_FragColor = vec4(gray, gray, gray, c.a);\n}',
defines: [
],
},
{
name: 'sprite',
vert: '\n \nuniform mat4 viewProj;\n#ifdef use2DPos\nattribute vec2 a_position;\n#else\nattribute vec3 a_position;\n#endif\nattribute vec4 a_color;\n#ifdef useModel\n uniform mat4 model;\n#endif\n#ifdef useTexture\n attribute vec2 a_uv0;\n varying vec2 uv0;\n#endif\n#ifndef useColor\nvarying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n mat4 mvp;\n #ifdef useModel\n mvp = viewProj * model;\n #else\n mvp = viewProj;\n #endif\n #ifdef use2DPos\n vec4 pos = mvp * vec4(a_position, 0, 1);\n #else\n vec4 pos = mvp * vec4(a_position, 1);\n #endif\n #ifndef useColor\n v_fragmentColor = a_color;\n #endif\n #ifdef useTexture\n uv0 = a_uv0;\n #endif\n gl_Position = pos;\n}',
frag: '\n \n#ifdef useTexture\n uniform sampler2D texture;\n varying vec2 uv0;\n#endif\n#ifdef alphaTest\n uniform float alphaThreshold;\n#endif\n#ifdef useColor\n uniform vec4 color;\n#else\n varying vec4 v_fragmentColor;\n#endif\nvoid main () {\n #ifdef useColor\n vec4 o = color;\n #else\n vec4 o = v_fragmentColor;\n #endif\n #ifdef useTexture\n o *= texture2D(texture, uv0);\n #endif\n #ifdef alphaTest\n if (o.a <= alphaThreshold)\n discard;\n #endif\n gl_FragColor = o;\n}',
vert: '\n \nuniform mat4 viewProj;\n#ifdef use2DPos\nattribute vec2 a_position;\n#else\nattribute vec3 a_position;\n#endif\nattribute lowp vec4 a_color;\n#ifdef useModel\n uniform mat4 model;\n#endif\n#ifdef useTexture\n attribute mediump vec2 a_uv0;\n varying mediump vec2 uv0;\n#endif\n#ifndef useColor\nvarying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n mat4 mvp;\n #ifdef useModel\n mvp = viewProj * model;\n #else\n mvp = viewProj;\n #endif\n #ifdef use2DPos\n vec4 pos = mvp * vec4(a_position, 0, 1);\n #else\n vec4 pos = mvp * vec4(a_position, 1);\n #endif\n #ifndef useColor\n v_fragmentColor = a_color;\n #endif\n #ifdef useTexture\n uv0 = a_uv0;\n #endif\n gl_Position = pos;\n}',
frag: '\n \n#ifdef useTexture\n uniform sampler2D texture;\n varying mediump vec2 uv0;\n#endif\n#ifdef alphaTest\n uniform lowp float alphaThreshold;\n#endif\n#ifdef useColor\n uniform lowp vec4 color;\n#else\n varying lowp vec4 v_fragmentColor;\n#endif\nvoid main () {\n #ifdef useColor\n vec4 o = color;\n #else\n vec4 o = v_fragmentColor;\n #endif\n #ifdef useTexture\n o *= texture2D(texture, uv0);\n #endif\n #ifdef alphaTest\n if (o.a <= alphaThreshold)\n discard;\n #endif\n gl_FragColor = o;\n}',
defines: [
{ name: 'useTexture', },
{ name: 'useModel', },
Expand Down Expand Up @@ -2959,7 +2959,7 @@ var StencilMaterial = (function (Material$$1) {
StencilMaterial.prototype = Object.create( Material$$1 && Material$$1.prototype );
StencilMaterial.prototype.constructor = StencilMaterial;

var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },useColor: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };
var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },useModel: { configurable: true },useColor: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };

prototypeAccessors.effect.get = function () {
return this._effect;
Expand All @@ -2973,6 +2973,14 @@ var StencilMaterial = (function (Material$$1) {
this._effect.define('useTexture', val);
};

prototypeAccessors.useModel.get = function () {
this._effect.getDefine('useModel');
};

prototypeAccessors.useModel.set = function (val) {
this._effect.define('useModel', val);
};

prototypeAccessors.useColor.get = function () {
this._effect.getDefine('useColor');
};
Expand Down Expand Up @@ -3004,6 +3012,7 @@ var StencilMaterial = (function (Material$$1) {
StencilMaterial.prototype.clone = function clone () {
var copy = new StencilMaterial();
copy.useTexture = this.useTexture;
copy.useModel = this.useModel;
copy.useColor = this.useColor;
copy.texture = this.texture;
copy.alphaThreshold = this.alphaThreshold;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/renderer/utils/label/ttf.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = {
url: url,
skips: [md5Pipe.id]
};
}
}
cc.loader.load(item, function (err) {
let localPath = wx.env.USER_DATA_PATH + '/' + url;
_fontFamily = wx.loadFont(localPath);
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/utils/affine-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ AffineTransform.transformSize = function (out, size, t) {
* !#en Apply the affine transformation on a rect.
* This function is memory free, you should create the output Rect by yourself and manage its memory.
* !#zh 应用仿射变换矩阵到 Rect 上。这个函数不创建任何内存,你需要先创建一个 Rect 对象用来存储结果,并作为第一个参数传入函数。
* @method transformRecta
* @method transformRect
* @static
* @param {Rect} out
* @param {Rect} rect
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ if (CC_DEV) {
_getError: 'cc.debug.getError',
_initDebugSetting: 'cc.debug._resetDebugSetting',
DebugMode: 'cc.debug.DebugMode',
BlendFunc: 'cc.macro.BlendFactor',
}, 'cc');
markAsRemovedInObject(cc, [
'BlendFunc',
'blendFuncDisable',

'pFromSize',
Expand Down
Loading

0 comments on commit 411e52b

Please sign in to comment.