src/level/LevelDirector.js
function loadTMXLevel(levelId, container, flatten, setViewportBounds) {
            var level = levels[levelId];

            // disable auto-sort for the given container
            var autoSort = container.autoSort;
            container.autoSort = false;

            var levelBounds = level.getBounds();

            if (setViewportBounds) {
                // update the viewport bounds
                me.game.viewport.setBounds(
                    0, 0,
                    Math.max(levelBounds.width, me.game.viewport.width),
                    Math.max(levelBounds.height, me.game.viewport.height)
                );
            }

            // reset the GUID generator
            // and pass the level id as parameter
            me.utils.resetGUID(levelId, level.nextobjectid);

            // Tiled use 0,0 anchor coordinates
            container.anchorPoint.set(0, 0);

            // add all level elements to the target container
            level.addTo(container, flatten);

            // sort everything (recursively)
            container.sort(true);
            container.autoSort = autoSort;

            container.resize(levelBounds.width, levelBounds.height);

            function resize_container() {
                // center the map if smaller than the current viewport
                container.pos.set(
                    Math.max(0, ~~((me.game.viewport.width - levelBounds.width) / 2)),
                    Math.max(0, ~~((me.game.viewport.height - levelBounds.height) / 2)),
                    0
                );
            }

            if (setViewportBounds) {
                resize_container();

                // Replace the resize handler
                if (onresize_handler) {
                    me.event.unsubscribe(onresize_handler);
                }
                onresize_handler = me.event.subscribe(me.event.VIEWPORT_ONRESIZE, resize_container);
            }
        }
function loadTMXLevel(levelId, container, flatten, setViewportBounds) {
            var level = levels[levelId];

            // disable auto-sort for the given container
            var autoSort = container.autoSort;
            container.autoSort = false;

            var levelBounds = level.getBounds();

            if (setViewportBounds) {
                // update the viewport bounds
                me.game.viewport.setBounds(
                    0, 0,
                    Math.max(levelBounds.width, me.game.viewport.width),
                    Math.max(levelBounds.height, me.game.viewport.height)
                );
            }

            // reset the GUID generator
            // and pass the level id as parameter
            me.utils.resetGUID(levelId, level.nextobjectid);

            // Tiled use 0,0 anchor coordinates
            container.anchorPoint.set(0, 0);

            // add all level elements to the target container
            level.addTo(container, flatten);

            // sort everything (recursively)
            container.sort(true);
            container.autoSort = autoSort;

            container.resize(levelBounds.width, levelBounds.height);

            function resize_container() {
                // center the map if smaller than the current viewport
                container.pos.set(
                    Math.max(0, ~~((me.game.viewport.width - levelBounds.width) / 2)),
                    Math.max(0, ~~((me.game.viewport.height - levelBounds.height) / 2)),
                    0
                );
            }

            if (setViewportBounds) {
                resize_container();

                // Replace the resize handler
                if (onresize_handler) {
                    me.event.unsubscribe(onresize_handler);
                }
                onresize_handler = me.event.subscribe(me.event.VIEWPORT_ONRESIZE, resize_container);
            }
        }
function loadTMXLevel ( levelId , container , flatten , setViewportBounds ) { var level = levels [ levelId ] ; // disable auto-sort for the given container var autoSort = container . autoSort ; container . autoSort = false ; var levelBounds = level . getBounds ( ) ; if ( setViewportBounds ) { // update the viewport bounds me . game . viewport . setBounds ( 0 , 0 , Math . max ( levelBounds . width , me . game . viewport . width ) , Math . max ( levelBounds . height , me . game . viewport . height ) ) ; } // reset the GUID generator // and pass the level id as parameter me . utils . resetGUID ( levelId , level . nextobjectid ) ; // Tiled use 0,0 anchor coordinates container . anchorPoint . set ( 0 , 0 ) ; // add all level elements to the target container level . addTo ( container , flatten ) ; // sort everything (recursively) container . sort ( true ) ; container . autoSort = autoSort ; container . resize ( levelBounds . width , levelBounds . height ) ; function resize_container ( ) { // center the map if smaller than the current viewport container . pos . set ( Math . max ( 0 , ~ ~ ( ( me . game . viewport . width - levelBounds . width ) / 2 ) ) , Math . max ( 0 , ~ ~ ( ( me . game . viewport . height - levelBounds . height ) / 2 ) ) , 0 ) ; } if ( setViewportBounds ) { resize_container ( ) ; // Replace the resize handler if ( onresize_handler ) { me . event . unsubscribe ( onresize_handler ) ; } onresize_handler = me . event . subscribe ( me . event . VIEWPORT_ONRESIZE , resize_container ) ; } }
Load a TMX level
@name loadTMXLevel
@memberOf me.game
@private
@param {String} level level id
@param {me.Container} target container
@param {boolean} flatten if true, flatten all objects into the given container
@param {boolean} setViewportBounds if true, set the viewport bounds to the map size
@ignore
@function
Load a TMX level