|
258 | 258 | boundingSet: function( options ) {
|
259 | 259 | var directions = ['left', 'right'];
|
260 | 260 |
|
261 |
| - var width = options.width || ( ( this.getPixels( options.radius ) + this.getPixels( options.stroke ) ) * 2 ); |
262 |
| - var height = options.height || ( ( this.getPixels( options.radius ) + this.getPixels( options.stroke ) ) * 2 ); |
263 |
| - |
264 |
| - var left = this.getPixels( options.x ); |
265 |
| - var right = this.getPixels( options.x ) + this.getPixels( width ); |
266 |
| - var top = this.getPixels( options.y ); |
267 |
| - var bottom = this.getPixels( options.y + height ); |
| 261 | + // Square - pivot is top left |
| 262 | + if( options.width ) |
| 263 | + { |
| 264 | + var width = this.getPixels( options.width ); |
| 265 | + var height = this.getPixels( options.height ); |
| 266 | + var left = this.getPixels( options.x ); |
| 267 | + var top = this.getPixels( options.y ); |
| 268 | + } |
| 269 | + // Circle - pivot is center |
| 270 | + else |
| 271 | + { |
| 272 | + if( this.options.touchRadius ) |
| 273 | + var radius = this.getPixels( options.radius ) * 2 + ( this.getPixels( this.options.touchRadius ) / 2 ); // size of the box the joystick can go to |
| 274 | + else |
| 275 | + var radius = options.radius; |
| 276 | + var width = height = ( radius + this.getPixels( options.stroke ) ) * 2; |
| 277 | + var left = this.getPixels( options.x ) - ( width / 2 ); |
| 278 | + var top = this.getPixels( options.y ) - ( height / 2 ); |
| 279 | + } |
| 280 | + var right = left + width; |
| 281 | + var bottom = top + height; |
268 | 282 |
|
269 | 283 | if( this.bound.left === false || left < this.bound.left )
|
270 | 284 | this.bound.left = left;
|
|
1117 | 1131 | */
|
1118 | 1132 | TouchableJoystick.prototype.check = function( touchX, touchY ) {
|
1119 | 1133 | if(
|
1120 |
| - ( Math.abs( touchX - this.x ) < this.radius + ( GameController.options.touchRadius / 2 ) ) && |
1121 |
| - ( Math.abs( touchY - this.y ) < this.radius + ( GameController.options.touchRadius / 2 ) ) |
| 1134 | + ( Math.abs( touchX - this.x ) < this.radius + ( GameController.getPixels( GameController.options.touchRadius ) / 2 ) ) && |
| 1135 | + ( Math.abs( touchY - this.y ) < this.radius + ( GameController.getPixels( GameController.options.touchRadius ) / 2 ) ) |
1122 | 1136 | )
|
1123 | 1137 | return true;
|
1124 | 1138 |
|
|
1172 | 1186 | {
|
1173 | 1187 | var subCanvas = document.createElement( 'canvas' );
|
1174 | 1188 | this.stroke = this.stroke || 2;
|
1175 |
| - subCanvas.width = subCanvas.height = 2 * ( this.radius + this.stroke ); |
| 1189 | + subCanvas.width = subCanvas.height = 2 * ( this.radius + ( GameController.options.touchRadius ) + this.stroke ); |
1176 | 1190 |
|
1177 | 1191 | var ctx = subCanvas.getContext( '2d' );
|
1178 | 1192 | ctx.lineWidth = this.stroke;
|
|
0 commit comments