@@ -371,6 +371,8 @@ Scene.prototype.render = function(pl) {
371
371
let sourcePitch = pl . pitch ;
372
372
let sourceWidth = pl . width ;
373
373
let sourceHeight = pl . height ;
374
+ let targetWidth = pl . width ;
375
+ let targetHeight = pl . height ;
374
376
let targetPitch = pl . width * 4 ;
375
377
let numPoints = pl . height * pl . width ;
376
378
let sizeInfo = null ;
@@ -404,6 +406,8 @@ Scene.prototype.render = function(pl) {
404
406
405
407
sourcePitch = this . tiles . tileWidth * pl . width ;
406
408
targetPitch = sourcePitch * 4 ;
409
+ targetWidth = this . tiles . tileWidth * pl . width ;
410
+ targetHeight = this . tiles . tileHeight * pl . height ;
407
411
numPoints = numPoints * tileSize ;
408
412
sizeInfo = { } ;
409
413
sizeInfo . width = this . tiles . tileWidth * pl . width ;
@@ -417,25 +421,42 @@ Scene.prototype.render = function(pl) {
417
421
418
422
let scrollY = Math . floor ( this . _config . scrollY || 0 ) ;
419
423
let scrollX = Math . floor ( this . _config . scrollX || 0 ) ;
420
-
421
- for ( let y = 0 ; y < sourceHeight ; y ++ ) {
422
- for ( let x = 0 ; x < sourceWidth ; x ++ ) {
423
- let k = ( y + scrollY ) * sourcePitch + x + scrollX ;
424
- let j = y * targetPitch + x * 4 ;
425
- if ( k < 0 || k >= source . length ) {
426
- this . rgbBuffer [ j + 0 ] = 0 ;
427
- this . rgbBuffer [ j + 1 ] = 0 ;
428
- this . rgbBuffer [ j + 2 ] = 0 ;
429
- this . rgbBuffer [ j + 3 ] = 0xff ;
430
- continue ;
424
+ scrollY = ( ( scrollY % sourceHeight ) + sourceHeight ) % sourceHeight ;
425
+ scrollX = ( ( scrollX % sourceWidth ) + sourceWidth ) % sourceWidth ;
426
+
427
+ for ( let attempt = 0 ; attempt < 4 ; attempt ++ ) {
428
+ for ( let y = 0 ; y < sourceHeight ; y ++ ) {
429
+ for ( let x = 0 ; x < sourceWidth ; x ++ ) {
430
+ let i , j ;
431
+ if ( attempt == 0 ) {
432
+ i = y - scrollY ;
433
+ j = x - scrollX ;
434
+ } else if ( attempt == 1 ) {
435
+ i = y - scrollY ;
436
+ j = x - scrollX + sourceWidth ;
437
+ } else if ( attempt == 2 ) {
438
+ i = y - scrollY + sourceHeight ;
439
+ j = x - scrollX ;
440
+ } else if ( attempt == 3 ) {
441
+ i = y - scrollY + sourceHeight ;
442
+ j = x - scrollX + sourceWidth ;
443
+ } else {
444
+ continue ;
445
+ }
446
+ if ( i < 0 || i >= targetHeight || j < 0 || j >= targetWidth ) {
447
+ continue ;
448
+ }
449
+ let s = y * sourcePitch + x ;
450
+ let t = i * targetPitch + j * 4 ;
451
+ let rgb = this . _toColor ( source [ s ] ) ;
452
+ this . rgbBuffer [ t + 0 ] = rgb . r ;
453
+ this . rgbBuffer [ t + 1 ] = rgb . g ;
454
+ this . rgbBuffer [ t + 2 ] = rgb . b ;
455
+ this . rgbBuffer [ t + 3 ] = 0xff ;
431
456
}
432
- let rgb = this . _toColor ( source [ k ] ) ;
433
- this . rgbBuffer [ j + 0 ] = rgb . r ;
434
- this . rgbBuffer [ j + 1 ] = rgb . g ;
435
- this . rgbBuffer [ j + 2 ] = rgb . b ;
436
- this . rgbBuffer [ j + 3 ] = 0xff ;
437
457
}
438
458
}
459
+
439
460
if ( sizeInfo ) {
440
461
this . rgbBuffer . width = sizeInfo . width ;
441
462
this . rgbBuffer . height = sizeInfo . height ;
0 commit comments