@@ -15,6 +15,17 @@ module Phaser {
1515
1616 export class ScrollZone extends GameObject {
1717
18+ /**
19+ * ScrollZone constructor
20+ * Create a new <code>ScrollZone</code>.
21+ *
22+ * @param game {Phaser.Game} Current game instance.
23+ * @param key {string} Asset key for image texture of this object.
24+ * @param x {number} X position in world coordinate.
25+ * @param y {number} Y position in world coordinate.
26+ * @param width {number} Optional, width of this object.
27+ * @param height {number} Optional, height of this object.
28+ */
1829 constructor ( game : Game , key :string , x : number = 0 , y : number = 0 , width ?: number = 0 , height ?: number = 0 ) {
1930
2031 super ( game , x , y , width , height ) ;
@@ -49,19 +60,63 @@ module Phaser {
4960
5061 }
5162
63+ /**
64+ * Texture of this object.
65+ */
5266 private _texture ;
67+ /**
68+ * If this zone is larger than texture image, this will be filled with a pattern of texture.
69+ * @type {DynamicTexture }
70+ */
5371 private _dynamicTexture : DynamicTexture = null ;
5472
55- // local rendering related temp vars to help avoid gc spikes
73+ /**
74+ * Local rendering related temp vars to help avoid gc spikes.
75+ * @type {number }
76+ */
5677 private _dx : number = 0 ;
78+ /**
79+ * Local rendering related temp vars to help avoid gc spikes.
80+ * @type {number }
81+ */
5782 private _dy : number = 0 ;
83+ /**
84+ * Local rendering related temp vars to help avoid gc spikes.
85+ * @type {number }
86+ */
5887 private _dw : number = 0 ;
88+ /**
89+ * Local rendering related temp vars to help avoid gc spikes.
90+ * @type {number }
91+ */
5992 private _dh : number = 0 ;
6093
94+ /**
95+ * Current region this zone is scrolling.
96+ * @type {ScrollRegion }
97+ */
6198 public currentRegion : ScrollRegion ;
99+ /**
100+ * Array contains all added regions.
101+ * @type {ScrollRegion[] }
102+ */
62103 public regions : ScrollRegion [ ] ;
104+ /**
105+ * Flip this zone vertically? (default to false)
106+ * @type {boolean }
107+ */
63108 public flipped : bool = false ;
64109
110+ /**
111+ * Add a new region to this zone.
112+ * @param x {number} X position of the new region.
113+ * @param y {number} Y position of the new region.
114+ * @param width {number} Width of the new region.
115+ * @param height {number} Height of the new region.
116+ * @param speedX {number} Optional, x-axis scrolling speed.
117+ * @param speedY {number} Optional, y-axis scrolling speed.
118+ * @return {ScrollRegion } The newly added region.
119+ */
65120 public addRegion ( x : number , y : number , width : number , height : number , speedX ?:number = 0 , speedY ?:number = 0 ) :ScrollRegion {
66121
67122 if ( x > this . width || y > this . height || x < 0 || y < 0 || ( x + width ) > this . width || ( y + height ) > this . height )
@@ -78,6 +133,11 @@ module Phaser {
78133
79134 }
80135
136+ /**
137+ * Set scrolling speed of current region.
138+ * @param x {number} X speed of current region.
139+ * @param y {number} Y speed of current region.
140+ */
81141 public setSpeed ( x : number , y : number ) {
82142
83143 if ( this . currentRegion )
@@ -89,6 +149,9 @@ module Phaser {
89149
90150 }
91151
152+ /**
153+ * Update regions.
154+ */
92155 public update ( ) {
93156
94157 for ( var i = 0 ; i < this . regions . length ; i ++ )
@@ -98,8 +161,13 @@ module Phaser {
98161
99162 }
100163
164+ /**
165+ * Check whether this zone is visible in a specific camera rectangle.
166+ * @param camera {Rectangle} The rectangle you want to check.
167+ * @return {boolean } Return true if bound of this zone intersects the given rectangle, otherwise return false.
168+ */
101169 public inCamera ( camera : Rectangle ) : bool {
102-
170+
103171 if ( this . scrollFactor . x !== 1.0 || this . scrollFactor . y !== 1.0 )
104172 {
105173 this . _dx = this . bounds . x - ( camera . x * this . scrollFactor . x ) ;
@@ -116,6 +184,13 @@ module Phaser {
116184
117185 }
118186
187+ /**
188+ * Render this zone object to a specific camera.
189+ * @param camera {Camera} The camera this object will be render to.
190+ * @param cameraOffsetX {number} X offset of camera.
191+ * @param cameraOffsetY {number} Y offset of camera.
192+ * @return Return false if not rendered, otherwise return true.
193+ */
119194 public render ( camera : Camera , cameraOffsetX : number , cameraOffsetY : number ) {
120195
121196 // Render checks
@@ -189,6 +264,10 @@ module Phaser {
189264
190265 }
191266
267+ /**
268+ * Create repeating texture with _texture, and store it into the _dynamicTexture.
269+ * Used to create texture when texture image is small than size of the zone.
270+ */
192271 private createRepeatingTexture ( regionWidth : number , regionHeight : number ) {
193272
194273 // Work out how many we'll need of the source image to make it tile properly
0 commit comments