cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

optional bounding box to the viewport to restrict camera to an area #50

Closed fariazz closed 11 years ago

fariazz commented 11 years ago

when adding the viewport to the player, you can new specify a bounding box so that the camera doesn't go outside of this box.

For example if you want to restrict the camera to the level, so that no areas outside the level are shown:

Q.scene("level1",function(stage) {

            var background = new Q.TileLayer({ dataAsset: 'level1.tmx', layerIndex: 0, sheet: 'tiles', tileW: 70, tileH: 70, type: Q.SPRITE_NONE });
            stage.insert(background);
            console.log(background);

            stage.collisionLayer(new Q.TileLayer({ dataAsset: 'level1.tmx', layerIndex:1,  sheet: 'tiles', tileW: 70, tileH: 70 }));

            var player = stage.insert(new Q.Player());

            stage.add("viewport").follow(player,{x: true, y: true},{minX: 0, maxX: background.p.w, minY: 0, maxY: background.p.h});

        });

See it in action here: http://static.pablofarias.com/boundingbox/