mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
Merge pull request #835 from knoxHuang/master
merge html5 code for #fireball/issues/2787
This commit is contained in:
@@ -293,6 +293,13 @@ var game = /** @lends cc.game# */{
|
||||
game.onStart();
|
||||
},
|
||||
|
||||
/**
|
||||
* End game, it will close the game window
|
||||
*/
|
||||
end: function () {
|
||||
close();
|
||||
},
|
||||
|
||||
// @Game loading
|
||||
/**
|
||||
* !#en Prepare game.
|
||||
|
||||
@@ -1161,6 +1161,7 @@ _ccsg.Node = cc.Class({
|
||||
if (this._isTransitionFinished)
|
||||
child.onEnterTransitionDidFinish();
|
||||
}
|
||||
child._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
if (this._cascadeColorEnabled)
|
||||
child._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty);
|
||||
if (this._cascadeOpacityEnabled)
|
||||
|
||||
@@ -117,6 +117,7 @@ cc.eventManager = {
|
||||
_nodePriorityMap: {},
|
||||
_globalZOrderNodeMap: {},
|
||||
_toAddedListeners: [],
|
||||
_toRemovedListeners: [],
|
||||
_dirtyNodes: [],
|
||||
_inDispatch: 0,
|
||||
_isEnabled: false,
|
||||
@@ -359,13 +360,17 @@ cc.eventManager = {
|
||||
|
||||
var fixedPriorityListeners = listeners.getFixedPriorityListeners();
|
||||
var sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
|
||||
var i, selListener;
|
||||
var i, selListener, idx, toRemovedListeners = this._toRemovedListeners;
|
||||
|
||||
if (sceneGraphPriorityListeners) {
|
||||
for (i = 0; i < sceneGraphPriorityListeners.length;) {
|
||||
selListener = sceneGraphPriorityListeners[i];
|
||||
if (!selListener._isRegistered()) {
|
||||
cc.js.array.remove(sceneGraphPriorityListeners, selListener);
|
||||
// if item in toRemove list, remove it from the list
|
||||
idx = toRemovedListeners.indexOf(selListener);
|
||||
if(idx !== -1)
|
||||
toRemovedListeners.splice(idx, 1);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
@@ -374,8 +379,13 @@ cc.eventManager = {
|
||||
if (fixedPriorityListeners) {
|
||||
for (i = 0; i < fixedPriorityListeners.length;) {
|
||||
selListener = fixedPriorityListeners[i];
|
||||
if (!selListener._isRegistered())
|
||||
if (!selListener._isRegistered()) {
|
||||
cc.js.array.remove(fixedPriorityListeners, selListener);
|
||||
// if item in toRemove list, remove it from the list
|
||||
idx = toRemovedListeners.indexOf(selListener);
|
||||
if(idx !== -1)
|
||||
toRemovedListeners.splice(idx, 1);
|
||||
}
|
||||
else
|
||||
++i;
|
||||
}
|
||||
@@ -416,6 +426,32 @@ cc.eventManager = {
|
||||
this._forceAddEventListener(locToAddedListeners[i]);
|
||||
this._toAddedListeners.length = 0;
|
||||
}
|
||||
|
||||
if(this._toRemovedListeners.length !== 0)
|
||||
this._cleanToRemovedListeners();
|
||||
},
|
||||
|
||||
//Remove all listeners in _toRemoveListeners list and cleanup
|
||||
_cleanToRemovedListeners: function() {
|
||||
var toRemovedListeners = this._toRemovedListeners;
|
||||
for(var i = 0; i< toRemovedListeners.length; i++) {
|
||||
var selListener = toRemovedListeners[i];
|
||||
var listeners = this._listenersMap[selListener._getListenerID()];
|
||||
if (!listeners)
|
||||
continue;
|
||||
|
||||
var idx, fixedPriorityListeners = listeners.getFixedPriorityListeners(), sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
|
||||
|
||||
if (sceneGraphPriorityListeners) {
|
||||
idx = sceneGraphPriorityListeners.indexOf(selListener);
|
||||
sceneGraphPriorityListeners.splice(idx, 1);
|
||||
}
|
||||
if (fixedPriorityListeners) {
|
||||
idx = fixedPriorityListeners.indexOf(selListener);
|
||||
fixedPriorityListeners.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
toRemovedListeners.length = 0;
|
||||
},
|
||||
|
||||
_onTouchEventCallback: function(listener, argsObj){
|
||||
@@ -787,6 +823,8 @@ cc.eventManager = {
|
||||
|
||||
if (this._inDispatch === 0)
|
||||
cc.js.array.remove(listeners, selListener);
|
||||
else
|
||||
this._toRemovedListeners.push(selListener);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,13 +108,8 @@ inputManager.didAccelerate = function (eventData) {
|
||||
z = (eventData["alpha"] / 90) * 0.981;
|
||||
}
|
||||
|
||||
if(cc.sys.os === cc.sys.OS_ANDROID){
|
||||
mAcceleration.x = -x;
|
||||
mAcceleration.y = -y;
|
||||
}else{
|
||||
mAcceleration.x = x;
|
||||
mAcceleration.y = y;
|
||||
}
|
||||
mAcceleration.x = x;
|
||||
mAcceleration.y = y;
|
||||
mAcceleration.z = z;
|
||||
|
||||
mAcceleration.timestamp = eventData.timeStamp || Date.now();
|
||||
|
||||
@@ -149,7 +149,7 @@ proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
w = locWidth * scaleX;
|
||||
h = locHeight * scaleY;
|
||||
|
||||
if (texture) {
|
||||
if (texture&& texture._htmlElementObj) {
|
||||
image = texture._htmlElementObj;
|
||||
if (texture._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, texture._pattern));
|
||||
|
||||
@@ -27,43 +27,43 @@
|
||||
* @class profiler
|
||||
*/
|
||||
cc.profiler = (function () {
|
||||
var _inited = false,
|
||||
_showFPS = false;
|
||||
var _frames = 0,
|
||||
_frameRate = 0,
|
||||
_lastSPF = 0,
|
||||
_accumDt = 0;
|
||||
var _FPSLabel = null,
|
||||
var _inited = false, _showFPS = false;
|
||||
var _frames = 0, _frameRate = 0, _lastSPF = 0, _accumDt = 0;
|
||||
var _afterVisitListener = null,
|
||||
_FPSLabel = null,
|
||||
_SPFLabel = null,
|
||||
_drawsLabel = null;
|
||||
|
||||
_drawsLabel = null,
|
||||
_fps = null;
|
||||
var LEVEL_DET_FACTOR = 0.6, _levelDetCycle = 10;
|
||||
var LEVELS = [0, 10, 20, 30];
|
||||
var _fpsCount = [0, 0, 0, 0];
|
||||
var _currLevel = 3, _analyseCount = 0, _totalFPS = 0;
|
||||
|
||||
var createStatsLabel = function () {
|
||||
var fontSize = 0;
|
||||
var w = cc.winSize.width, h = cc.winSize.height;
|
||||
var locStatsPosition = cc.macro.DIRECTOR_STATS_POSITION;
|
||||
if (w > h)
|
||||
fontSize = 0 | (h / 320 * 20);
|
||||
else
|
||||
fontSize = 0 | (w / 320 * 20);
|
||||
_FPSLabel = document.createElement('div');
|
||||
_SPFLabel = document.createElement('div');
|
||||
_drawsLabel = document.createElement('div');
|
||||
_fps = document.createElement('div');
|
||||
|
||||
_FPSLabel = new _ccsg.Label("000.0", "Arial");
|
||||
_SPFLabel = new _ccsg.Label("0.000", "Arial");
|
||||
_drawsLabel = new _ccsg.Label("0000", "Arial");
|
||||
_FPSLabel.setFontSize(fontSize);
|
||||
_SPFLabel.setFontSize(fontSize);
|
||||
_drawsLabel.setFontSize(fontSize);
|
||||
_FPSLabel.setContentSize(120, 40);
|
||||
_SPFLabel.setContentSize(120, 40);
|
||||
_drawsLabel.setContentSize(120, 40);
|
||||
_fps.id = 'fps';
|
||||
_fps.style.position = 'absolute';
|
||||
_fps.style.padding = '3px';
|
||||
_fps.style.textAlign = 'left';
|
||||
_fps.style.backgroundColor = 'rgb(0, 0, 34)';
|
||||
_fps.style.bottom = cc.macro.DIRECTOR_STATS_POSITION.y + '0px';
|
||||
_fps.style.left = cc.macro.DIRECTOR_STATS_POSITION.x + 'px';
|
||||
_fps.style.width = '45px';
|
||||
_fps.style.height = '60px';
|
||||
|
||||
_drawsLabel.setPosition(_drawsLabel.width / 2 + locStatsPosition.x, 40 * 5 / 2 + locStatsPosition.y);
|
||||
_SPFLabel.setPosition(_SPFLabel.width / 2 + locStatsPosition.x, 40 * 3 / 2 + locStatsPosition.y);
|
||||
_FPSLabel.setPosition(_FPSLabel.width / 2 + locStatsPosition.x, 40 / 2 + locStatsPosition.y);
|
||||
var labels = [_drawsLabel, _SPFLabel, _FPSLabel];
|
||||
for (var i = 0; i < 3; ++i) {
|
||||
var style = labels[i].style;
|
||||
style.color = 'rgb(0, 255, 255)';
|
||||
style.font = 'bold 12px Helvetica, Arial';
|
||||
style.lineHeight = '20px';
|
||||
style.width = '100%';
|
||||
_fps.appendChild(labels[i]);
|
||||
}
|
||||
};
|
||||
|
||||
var analyseFPS = function (fps) {
|
||||
@@ -120,29 +120,11 @@ cc.profiler = (function () {
|
||||
}
|
||||
|
||||
if (_showFPS) {
|
||||
_SPFLabel.setString(_lastSPF.toFixed(3));
|
||||
_FPSLabel.setString(_frameRate.toFixed(1));
|
||||
_drawsLabel.setString((0 | cc.g_NumberOfDraws).toString());
|
||||
_SPFLabel.innerText = _lastSPF.toFixed(3);
|
||||
_FPSLabel.innerText = _frameRate.toFixed(1);
|
||||
_drawsLabel.innerText = (0 | cc.g_NumberOfDraws).toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (_showFPS) {
|
||||
_FPSLabel.visit();
|
||||
_SPFLabel.visit();
|
||||
_drawsLabel.visit();
|
||||
}
|
||||
};
|
||||
|
||||
var afterProjection = function(){
|
||||
if (_FPSLabel) {
|
||||
_FPSLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
}
|
||||
if (_SPFLabel) {
|
||||
_SPFLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
}
|
||||
if (_drawsLabel) {
|
||||
_drawsLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
}
|
||||
};
|
||||
|
||||
var profiler = {
|
||||
@@ -163,12 +145,10 @@ cc.profiler = (function () {
|
||||
|
||||
resumeProfiling: function () {
|
||||
cc.director.on(cc.Director.EVENT_AFTER_VISIT, afterVisit);
|
||||
cc.director.on(cc.Director.EVENT_PROJECTION_CHANGED, afterProjection);
|
||||
},
|
||||
|
||||
stopProfiling: function () {
|
||||
cc.director.off(cc.Director.EVENT_AFTER_VISIT, afterVisit);
|
||||
cc.director.off(cc.Director.EVENT_PROJECTION_CHANGED, afterProjection);
|
||||
},
|
||||
|
||||
isShowingStats: function () {
|
||||
@@ -176,24 +156,25 @@ cc.profiler = (function () {
|
||||
},
|
||||
|
||||
showStats: function () {
|
||||
if (_ccsg.Label && !_FPSLabel) {
|
||||
createStatsLabel();
|
||||
}
|
||||
if (_FPSLabel) {
|
||||
_showFPS = true;
|
||||
}
|
||||
if (!_inited) {
|
||||
this.init();
|
||||
}
|
||||
if (_fps.parentElement === null) {
|
||||
cc.container.appendChild(_fps);
|
||||
}
|
||||
_showFPS = true;
|
||||
},
|
||||
|
||||
hideStats: function () {
|
||||
_showFPS = false;
|
||||
cc.renderer.childrenOrderDirty = true;
|
||||
if (_fps.parentElement === cc.container) {
|
||||
cc.container.removeChild(_fps);
|
||||
}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
if (!_inited) {
|
||||
createStatsLabel();
|
||||
this.resumeProfiling();
|
||||
_inited = true;
|
||||
}
|
||||
|
||||
@@ -24,5 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCPath');
|
||||
require('./CCProfiler');
|
||||
if (!CC_EDITOR && !CC_JSB) {
|
||||
require('./CCProfiler');
|
||||
}
|
||||
require('./find');
|
||||
|
||||
@@ -210,7 +210,7 @@ var TestController = cc.LayerGradient.extend({
|
||||
onCloseCallback:function () {
|
||||
if (cc.sys.isNative)
|
||||
{
|
||||
cc.director.end();
|
||||
cc.game.end();
|
||||
}
|
||||
else {
|
||||
window.history && window.history.go(-1);
|
||||
|
||||
Reference in New Issue
Block a user