Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ cc.loader = (function () {

var self = this;
var errorCallback = function () {
this.removeEventListener('load', loadCallback, false);
this.removeEventListener('error', errorCallback, false);

if (img.crossOrigin && img.crossOrigin.toLowerCase() === "anonymous") {
Expand Down Expand Up @@ -1757,7 +1758,7 @@ var _initSys = function () {
sys.browserVersion = "";
/* Determine the browser version number */
(function(){
var versionReg1 = /(micromessenger|qq|mx|maxthon|baidu|sogou)(mobile)?(browser)?\/?([\d.]+)/i;
var versionReg1 = /(micromessenger|mqqbrowser|qq|maxthon|baidu|sogou)(mobile)?(browser)?\/?([\d.]+)/i;
var versionReg2 = /(msie |rv:|firefox|chrome|ucbrowser|oupeng|opera|opr|safari|miui)(mobile)?(browser)?\/?([\d.]+)/i;
var tmp = ua.match(versionReg1);
if(!tmp) tmp = ua.match(versionReg2);
Expand Down Expand Up @@ -1844,7 +1845,7 @@ var _initSys = function () {
var tmpCanvas = document.createElement("CANVAS");
try{
var context = cc.create3DContext(tmpCanvas);
if (context && context.getShaderPrecisionFormat) {
if (context) {
_supportWebGL = true;
}

Expand Down Expand Up @@ -2330,6 +2331,7 @@ cc.game = /** @lends cc.game# */{
config[CONFIG_KEY.frameRate] = frameRate;
if (self._intervalId)
window.cancelAnimationFrame(self._intervalId);
self._intervalId = 0;
self._paused = true;
self._setAnimFrame();
self._runMainLoop();
Expand Down Expand Up @@ -2512,8 +2514,9 @@ cc.game = /** @lends cc.game# */{
// @Time ticker section
_setAnimFrame: function () {
this._lastTime = new Date();
this._frameTime = 1000 / cc.game.config[cc.game.CONFIG_KEY.frameRate];
if ((cc.sys.os === cc.sys.OS_IOS && cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT) || cc.game.config[cc.game.CONFIG_KEY.frameRate] !== 60) {
var frameRate = cc.game.config[cc.game.CONFIG_KEY.frameRate];
this._frameTime = 1000 / frameRate;
if (frameRate !== 60 && frameRate !== 30) {
window.requestAnimFrame = this._stTime;
window.cancelAnimationFrame = this._ctTime;
}
Expand Down Expand Up @@ -2551,20 +2554,26 @@ cc.game = /** @lends cc.game# */{
//Run game.
_runMainLoop: function () {
var self = this, callback, config = self.config, CONFIG_KEY = self.CONFIG_KEY,
director = cc.director;
director = cc.director,
skip = true, frameRate = config[CONFIG_KEY.frameRate];

director.setDisplayStats(config[CONFIG_KEY.showFPS]);

callback = function () {
if (!self._paused) {
if (frameRate === 30) {
if (skip = !skip) {
self._intervalId = window.requestAnimFrame(callback);
return;
}
}

director.mainLoop();
if (self._intervalId)
window.cancelAnimationFrame(self._intervalId);
self._intervalId = window.requestAnimFrame(callback);
}
};

window.requestAnimFrame(callback);
self._intervalId = window.requestAnimFrame(callback);
self._paused = false;
},

Expand Down
13 changes: 12 additions & 1 deletion cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
THE SOFTWARE.
****************************************************************************/

function setProgram (node, program) {
node.shaderProgram = program;

var children = node.children;
if (!children)
return;

for (var i = 0; i < children.length; i++)
setProgram(children[i], program);
}

// ------------------------------- ClippingNode's WebGL render cmd ------------------------------
(function () {
cc.ClippingNode.WebGLRenderCmd = function (renderable) {
Expand Down Expand Up @@ -128,7 +139,7 @@
var node = this._node;
if (node._stencil) {
var program = node._originStencilProgram;
cc.setProgram(node._stencil, program);
setProgram(node._stencil, program);
}
};

Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
convertToGL: function (uiPoint) {
var docElem = document.documentElement;
var view = cc.view;
var box = element.getBoundingClientRect();
var box = docElem.getBoundingClientRect();
box.left += window.pageXOffset - docElem.clientLeft;
box.top += window.pageYOffset - docElem.clientTop;
var x = view._devicePixelRatio * (uiPoint.x - box.left);
Expand All @@ -202,7 +202,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
convertToUI: function (glPoint) {
var docElem = document.documentElement;
var view = cc.view;
var box = element.getBoundingClientRect();
var box = docElem.getBoundingClientRect();
box.left += window.pageXOffset - docElem.clientLeft;
box.top += window.pageYOffset - docElem.clientTop;
var uiPoint = {x: 0, y: 0};
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/base-nodes/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
updateTransform: function () {
var children = this._children, node;
for (var i = 0; i < children.length; i++) {
varnode = children[i];
var node = children[i];
if (node)
node.updateTransform();
}
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/layers/CCLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
return true;
},

visit: function () {
visit: function (parent) {
// quick return if not visible
if (!this._visible)
return;
Expand Down
46 changes: 29 additions & 17 deletions cocos2d/core/platform/CCEGLView.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
_resizeCallback: null,

_orientationChanging: true,
_resizing: false,

_scaleX: 1,
_originalScaleX: 1,
Expand Down Expand Up @@ -187,8 +188,6 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
_t._viewName = "Cocos2dHTML5";

var sys = cc.sys;
_t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX);
_t.enableAutoFullScreen(sys.isMobile && sys.browserType !== sys.BROWSER_TYPE_BAIDU);
cc.visibleRect && cc.visibleRect.init(_t._visibleRect);

// Setup system default resolution policies
Expand All @@ -212,15 +211,29 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{

// Check frame size changed or not
var prevFrameW = view._frameSize.width, prevFrameH = view._frameSize.height, prevRotated = view._isRotated;
view._initFrameSize();
if (cc.sys.isMobile) {
var containerStyle = cc.game.container.style,
margin = containerStyle.margin;
containerStyle.margin = '0';
containerStyle.display = 'none';
view._initFrameSize();
containerStyle.margin = margin;
containerStyle.display = 'block';
}
else {
view._initFrameSize();
}
if (view._isRotated === prevRotated && view._frameSize.width === prevFrameW && view._frameSize.height === prevFrameH)
return;

// Frame size changed, do resize works
var width = view._originalDesignResolutionSize.width;
var height = view._originalDesignResolutionSize.height;
if (width > 0)
view._resizing = true;
if (width > 0) {
view.setDesignResolutionSize(width, height, view._resolutionPolicy);
}
view._resizing = false;

cc.eventManager.dispatchCustomEvent('canvas-resize');
if (view._resizeCallback) {
Expand Down Expand Up @@ -347,9 +360,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
cc.container.style.transformOrigin = '0px 0px 0px';
this._isRotated = true;
}
setTimeout(function () {
cc.view._orientationChanging = false;
}, 1000);
if (this._orientationChanging) {
setTimeout(function () {
cc.view._orientationChanging = false;
}, 1000);
}
},

// hack
Expand Down Expand Up @@ -482,12 +497,6 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
return this._autoFullScreen;
},

/**
* Force destroying EGL view, subclass must implement this method.
*/
end: function () {
},

/**
* Get whether render system is ready(no matter opengl or canvas),<br/>
* this name is for the compatibility with cocos2d-x, subclass must implement this method.
Expand Down Expand Up @@ -688,7 +697,8 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{

// Permit to re-detect the orientation of device.
this._orientationChanging = true;
this._initFrameSize();
if (!this._resizing)
this._initFrameSize();

if (!policy) {
cc.log(cc._LogInfos.EGLView_setDesignResolutionSize_2);
Expand Down Expand Up @@ -771,8 +781,10 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
this._setViewportMeta({"width": width}, true);

// Set body width to the exact pixel resolution
document.documentElement.style.width = width + 'px';
document.body.style.width = "100%";
document.documentElement.style.width = width + "px";
document.body.style.width = width + "px";
document.body.style.left = "0px";
document.body.style.top = "0px";

// Reset the resolution size and policy
this.setDesignResolutionSize(width, height, resolutionPolicy);
Expand Down Expand Up @@ -985,7 +997,7 @@ cc.ContainerStrategy = cc.Class.extend(/** @lends cc.ContainerStrategy# */{

_setupContainer: function (view, w, h) {
var locCanvas = cc.game.canvas, locContainer = cc.game.container;
if (cc.sys.isMobile) {
if (cc.sys.os === cc.sys.OS_ANDROID) {
document.body.style.width = (view._isRotated ? h : w) + 'px';
document.body.style.height = (view._isRotated ? w : h) + 'px';
}
Expand Down
3 changes: 2 additions & 1 deletion cocos2d/core/scenes/CCLoaderScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
cc.LoaderScene = cc.Scene.extend({
_interval : null,
_label : null,
_logo : null,
_className:"LoaderScene",
cb: null,
target: null,
Expand Down Expand Up @@ -132,7 +133,7 @@ cc.LoaderScene = cc.Scene.extend({
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
this._bgLayer._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
this._label._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
this._logo._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
this._logo && this._logo._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
}
});
/**
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/sprites/CCSpriteFrameCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ cc.spriteFrameCache = /** @lends cc.spriteFrameCache# */{
var frame = frames[key];
var spriteFrame = spriteFrames[key];
if (!spriteFrame) {
spriteFrame = new cc.SpriteFrame(texture, frame.rect, frame.rotated, frame.offset, frame.size);
spriteFrame = new cc.SpriteFrame(texture, cc.rect(frame.rect), frame.rotated, frame.offset, frame.size);
var aliases = frame.aliases;
if (aliases) {//set aliases
for (var i = 0, li = aliases.length; i < li; i++) {
Expand Down
10 changes: 6 additions & 4 deletions cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@
node._texture = texture;

// Update texture rect and blend func
var texSize = texture._contentSize;
var rect = cc.rect(0, 0, texSize.width, texSize.height);
node.setTextureRect(rect);
this._updateBlendFunc();
if (texture) {
var texSize = texture._contentSize;
var rect = cc.rect(0, 0, texSize.width, texSize.height);
node.setTextureRect(rect);
this._updateBlendFunc();
}

if (node._textureLoaded) {
// Force refresh the render command list
Expand Down
4 changes: 3 additions & 1 deletion cocos2d/core/support/CCPointExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,7 @@ cc.pAddIn = function(v1, v2) {
* @param {cc.Point} v
*/
cc.pNormalizeIn = function(v) {
cc.pMultIn(v, 1.0 / Math.sqrt(v.x * v.x + v.y * v.y));
var n = Math.sqrt(v.x * v.x + v.y * v.y);
if (n !== 0)
cc.pMultIn(v, 1.0 / n);
};
4 changes: 2 additions & 2 deletions cocos2d/shaders/CCGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ cc.GLProgram.create = function (vShaderFileName, fShaderFileName) {
cc.GLProgram._highpSupported = null;

cc.GLProgram._isHighpSupported = function () {
if (cc.GLProgram._highpSupported == null) {
var ctx = cc._renderContext;
var ctx = cc._renderContext;
if (ctx.getShaderPrecisionFormat && cc.GLProgram._highpSupported == null) {
var highp = ctx.getShaderPrecisionFormat(ctx.FRAGMENT_SHADER, ctx.HIGH_FLOAT);
cc.GLProgram._highpSupported = highp.precision !== 0;
}
Expand Down
Loading