1+ var Rectangle = require ( '../geom/rectangle/Rectangle' ) ;
12var TransformMatrix = require ( '../components/TransformMatrix' ) ;
23
34var Camera = function ( x , y , width , height )
@@ -7,6 +8,9 @@ var Camera = function (x, y, width, height)
78 this . width = width ;
89 this . height = height ;
910
11+ this . useBounds = false ;
12+ this . _bounds = new Rectangle ( ) ;
13+
1014 this . scrollX = 0.0 ;
1115 this . scrollY = 0.0 ;
1216 this . zoom = 1.0 ;
@@ -41,23 +45,47 @@ Camera.prototype.constructor = Camera;
4145
4246Camera . prototype = {
4347
48+ removeBounds : function ( )
49+ {
50+ this . useBounds = false ;
51+
52+ this . _bounds . setEmpty ( ) ;
53+
54+ return this ;
55+ } ,
56+
57+ setBounds : function ( x , y , width , height )
58+ {
59+ this . _bounds . setTo ( x , y , width , height ) ;
60+
61+ this . useBounds = true ;
62+
63+ return this ;
64+ } ,
65+
4466 setViewport : function ( x , y , width , height )
4567 {
4668 this . x = x ;
4769 this . y = y ;
4870 this . width = width ;
4971 this . height = height ;
72+
73+ return this ;
5074 } ,
5175
5276 setSize : function ( width , height )
5377 {
5478 this . width = width ;
5579 this . height = height ;
80+
81+ return this ;
5682 } ,
5783
5884 setState : function ( state )
5985 {
6086 this . state = state ;
87+
88+ return this ;
6189 } ,
6290
6391 update : function ( delta )
@@ -111,7 +139,7 @@ Camera.prototype = {
111139 this . _follow = gameObjectOrPoint ;
112140 } ,
113141
114- stopFollow : function ( )
142+ stopFollow : function ( )
115143 {
116144 /* do unfollow work here */
117145 this . _follow = null ;
@@ -199,6 +227,29 @@ Camera.prototype = {
199227 this . scrollY = originY - height * 0.5 ;
200228 }
201229
230+ if ( this . useBounds )
231+ {
232+ var bounds = this . _bounds ;
233+
234+ if ( this . scrollX < bounds . x )
235+ {
236+ this . scrollX = bounds . x ;
237+ }
238+ else if ( this . scrollX > bounds . right )
239+ {
240+ this . scrollX = bounds . right ;
241+ }
242+
243+ if ( this . scrollY < bounds . y )
244+ {
245+ this . scrollY = bounds . y ;
246+ }
247+ else if ( this . scrollY > bounds . bottom )
248+ {
249+ this . scrollY = bounds . bottom ;
250+ }
251+ }
252+
202253 matrix . loadIdentity ( ) ;
203254 matrix . translate ( this . x + originX , this . y + originY ) ;
204255 matrix . rotate ( this . rotation ) ;
0 commit comments