@@ -285,7 +285,7 @@ cc.DOM.methods = /** @lends cc.DOM# */{
285285 redraw :function ( ) {
286286 if ( this . isSprite ) {
287287 var tmp = this . _children ;
288- this . _children = null ;
288+ this . _children = [ ] ;
289289 cc . Sprite . prototype . visit . call ( this , this . ctx ) ;
290290 this . _children = tmp ;
291291 }
@@ -315,16 +315,25 @@ cc.DOM._resetEGLViewDiv = function(){
315315 }
316316
317317 eglViewDiv . style . position = 'absolute' ;
318- eglViewDiv . style . bottom = 0 ;
319318 //x.dom.style.display='block';
320319 eglViewDiv . style . width = designSizeWidth + "px" ;
321320 eglViewDiv . style . maxHeight = designSizeHeight + "px" ;
322321 eglViewDiv . style . margin = 0 ;
323322
324323 eglViewDiv . resize ( eglViewer . getScaleX ( ) , eglViewer . getScaleY ( ) ) ;
325- eglViewDiv . style . left = ( ( viewPortWidth - designSizeWidth ) / 2
326- + ( screenSize . width - viewPortWidth ) / 2 ) + "px" ;
327- eglViewDiv . style . bottom = ( ( screenSize . height - viewPortHeight ) / 2 ) + "px" ;
324+
325+ if ( viewPortWidth < screenSize . width ) {
326+ eglViewDiv . style . left = ( ( viewPortWidth - designSizeWidth ) / 2
327+ + ( screenSize . width - viewPortWidth ) / 2 ) + "px" ;
328+ } else {
329+ eglViewDiv . style . left = ( viewPortWidth - designSizeWidth ) / 2 + "px" ;
330+ }
331+
332+ if ( viewPortHeight < screenSize . height ) {
333+ eglViewDiv . style . bottom = ( ( screenSize . height - viewPortHeight ) / 2 ) + "px" ;
334+ } else {
335+ eglViewDiv . style . bottom = "0px" ;
336+ }
328337 }
329338} ;
330339
@@ -351,47 +360,56 @@ cc.DOM.parentDOM = function (x) {
351360 cc . DOM . parentDOM ( p ) ;
352361 } else {
353362 //parent has no more parent, if its running, then add it to the container
354- //if (p.isRunning()) {
355- //find EGLView div
356- var eglViewDiv = cc . $ ( "#EGLViewDiv" ) ;
357- if ( eglViewDiv ) {
358- p . dom . appendTo ( eglViewDiv ) ;
359- } else {
360- eglViewDiv = cc . $new ( "div" ) ;
361- eglViewDiv . id = "EGLViewDiv" ;
362-
363- var eglViewer = cc . EGLView . getInstance ( ) ;
364- var designSize = eglViewer . getDesignResolutionSize ( ) ;
365- var viewPortRect = eglViewer . getViewPortRect ( ) ;
366- var screenSize = eglViewer . getFrameSize ( ) ;
367- var designSizeWidth = designSize . width , designSizeHeight = designSize . height ;
368- if ( ( designSize . width === 0 ) && ( designSize . height === 0 ) ) {
369- designSizeWidth = screenSize . width ;
370- designSizeHeight = screenSize . height ;
371- }
372-
373- var viewPortWidth = viewPortRect . size . width , viewPortHeight = viewPortRect . size . height ;
374- if ( ( viewPortRect . size . width === 0 ) && ( viewPortRect . size . height === 0 ) ) {
375- viewPortWidth = screenSize . width ;
376- viewPortHeight = screenSize . height ;
363+ if ( p . isRunning ( ) ) {
364+ //find EGLView div
365+ var eglViewDiv = cc . $ ( "#EGLViewDiv" ) ;
366+ if ( eglViewDiv ) {
367+ p . dom . appendTo ( eglViewDiv ) ;
368+ } else {
369+ eglViewDiv = cc . $new ( "div" ) ;
370+ eglViewDiv . id = "EGLViewDiv" ;
371+
372+ var eglViewer = cc . EGLView . getInstance ( ) ;
373+ var designSize = eglViewer . getDesignResolutionSize ( ) ;
374+ var viewPortRect = eglViewer . getViewPortRect ( ) ;
375+ var screenSize = eglViewer . getFrameSize ( ) ;
376+ var designSizeWidth = designSize . width , designSizeHeight = designSize . height ;
377+ if ( ( designSize . width === 0 ) && ( designSize . height === 0 ) ) {
378+ designSizeWidth = screenSize . width ;
379+ designSizeHeight = screenSize . height ;
380+ }
381+
382+ var viewPortWidth = viewPortRect . size . width , viewPortHeight = viewPortRect . size . height ;
383+ if ( ( viewPortRect . size . width === 0 ) && ( viewPortRect . size . height === 0 ) ) {
384+ viewPortWidth = screenSize . width ;
385+ viewPortHeight = screenSize . height ;
386+ }
387+
388+ eglViewDiv . style . position = 'absolute' ;
389+ //x.dom.style.display='block';
390+ eglViewDiv . style . width = designSizeWidth + "px" ;
391+ eglViewDiv . style . maxHeight = designSizeHeight + "px" ;
392+ eglViewDiv . style . margin = 0 ;
393+
394+ eglViewDiv . resize ( eglViewer . getScaleX ( ) , eglViewer . getScaleY ( ) ) ;
395+
396+ if ( viewPortWidth < screenSize . width ) {
397+ eglViewDiv . style . left = ( ( viewPortWidth - designSizeWidth ) / 2
398+ + ( screenSize . width - viewPortWidth ) / 2 ) + "px" ;
399+ } else {
400+ eglViewDiv . style . left = ( viewPortWidth - designSizeWidth ) / 2 + "px" ;
401+ }
402+
403+ if ( viewPortHeight < screenSize . height ) {
404+ eglViewDiv . style . bottom = ( ( screenSize . height - viewPortHeight ) / 2 ) + "px" ;
405+ } else {
406+ eglViewDiv . style . bottom = "0px" ;
407+ }
408+
409+ p . dom . appendTo ( eglViewDiv ) ;
410+ eglViewDiv . appendTo ( cc . container ) ;
377411 }
378-
379- eglViewDiv . style . position = 'absolute' ;
380- eglViewDiv . style . bottom = 0 ;
381- //x.dom.style.display='block';
382- eglViewDiv . style . width = designSizeWidth + "px" ;
383- eglViewDiv . style . maxHeight = designSizeHeight + "px" ;
384- eglViewDiv . style . margin = 0 ;
385-
386- eglViewDiv . resize ( eglViewer . getScaleX ( ) , eglViewer . getScaleY ( ) ) ;
387- eglViewDiv . style . left = ( ( viewPortWidth - designSizeWidth ) / 2
388- + ( screenSize . width - viewPortWidth ) / 2 ) + "px" ;
389- eglViewDiv . style . bottom = ( ( screenSize . height - viewPortHeight ) / 2 ) + "px" ;
390-
391- p . dom . appendTo ( eglViewDiv ) ;
392- eglViewDiv . appendTo ( cc . container ) ;
393412 }
394- //}
395413 }
396414 return true ;
397415} ;
@@ -410,7 +428,7 @@ cc.DOM.setTransform = function (x) {
410428 x . ctx . translate ( x . getAnchorPointInPoints ( ) . x , x . getAnchorPointInPoints ( ) . y ) ;
411429 if ( x . isSprite ) {
412430 var tmp = x . _children ;
413- x . _children = null ;
431+ x . _children = [ ] ;
414432 cc . Sprite . prototype . visit . call ( x , x . ctx ) ;
415433 x . _children = tmp ;
416434 }
0 commit comments