Closed fariazz closed 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/
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:
See it in action here: http://static.pablofarias.com/boundingbox/