Skip to content

Commit d604622

Browse files
author
pandamicro
committed
Made orientation more reasonable
1 parent b9738ae commit d604622

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cocos2d/core/platform/CCEGLView.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
138138
_viewName: "",
139139
// Custom callback for resize event
140140
_resizeCallback: null,
141+
142+
_orientationChanging: true,
143+
141144
_scaleX: 1,
142145
_originalScaleX: 1,
143146
_scaleY: 1,
@@ -224,6 +227,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
224227
}
225228
},
226229

230+
_orientationChange: function () {
231+
this._orientationChanging = true;
232+
this._resizeEvent();
233+
},
234+
227235
/**
228236
* <p>
229237
* Sets view's target-densitydpi for android mobile browser. it can be set to: <br/>
@@ -259,14 +267,14 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
259267
if (!this.__resizeWithBrowserSize) {
260268
this.__resizeWithBrowserSize = true;
261269
window.addEventListener('resize', this._resizeEvent);
262-
window.addEventListener('orientationchange', this._resizeEvent);
270+
window.addEventListener('orientationchange', this._orientationChange);
263271
}
264272
} else {
265273
//disable
266274
if (this.__resizeWithBrowserSize) {
267275
this.__resizeWithBrowserSize = false;
268276
window.removeEventListener('resize', this._resizeEvent);
269-
window.removeEventListener('orientationchange', this._resizeEvent);
277+
window.removeEventListener('orientationchange', this._orientationChange);
270278
}
271279
}
272280
},
@@ -305,7 +313,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
305313
var h = __BrowserGetter.availHeight(this._frame);
306314
var isLandscape = w >= h;
307315

308-
if (!cc.sys.isMobile ||
316+
if (!this._orientationChanging || !cc.sys.isMobile ||
309317
(isLandscape && this._orientation & cc.ORIENTATION_LANDSCAPE) ||
310318
(!isLandscape && this._orientation & cc.ORIENTATION_PORTRAIT)) {
311319
locFrameSize.width = w;
@@ -323,6 +331,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
323331
cc.container.style.transformOrigin = '0px 0px 0px';
324332
this._isRotated = true;
325333
}
334+
this._orientationChanging = false;
326335
},
327336

328337
// hack

0 commit comments

Comments
 (0)