Skip to content

Commit

Permalink
Ticket #124 : add repeat property handling
Browse files Browse the repository at this point in the history
  • Loading branch information
obiot committed Oct 31, 2012
1 parent 0ae7e86 commit 5a82891
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/level/TMXLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
* @type String
* @name me.ImageLayer#repeat
*/
repeat: 'repeat',
//repeat: 'repeat', (define through getter/setter

/**
* Define the image scrolling ratio<br>
Expand Down Expand Up @@ -171,7 +171,38 @@
this.floating = true;

// default value for repeat
this.repeat = 'repeat';
this._repeat = 'repeat';

this.repeatX = true;
this.repeatY = true;

Object.defineProperty(this, "repeat", {
get : function get() {
return this._repeat;
},
set : function set(val) {
this._repeat = val;
switch (this._repeat) {
case "no-repeat" :
this.repeatX = false;
this.repeatY = false;
break;
case "repeat-x" :
this.repeatX = true;
this.repeatY = false;
break;
case "repeat-y" :
this.repeatX = false;
this.repeatY = true;
break;
default : // "repeat"
this.repeatX = true;
this.repeatY = true;
break;
}
}
});


},

Expand Down Expand Up @@ -257,16 +288,17 @@
rect.left, rect.top, //dx, dy
sw, sh); //dw, dh
}
// parallax / scrolling image
// parallax / scrolling image
// todo ; broken with dirtyRect enabled
else {
var sx = ~~this.offset.x;
var sy = ~~this.offset.y;

var dx = 0;
var dy = 0;

var sw = Math.min(this.imagewidth - ~~this.offset.x, this.width);
var sh = Math.min(this.imageheight - ~~this.offset.y, this.height);
var sw = Math.min(this.imagewidth - sx, this.width);
var sh = Math.min(this.imageheight - sy, this.height);

do {
do {
Expand All @@ -279,9 +311,9 @@
sy = 0;
dy += sh;
sh = Math.min(this.imageheight, this.height - dy);
} while( dy < this.height);
} while( this.repeatY && (dy < this.height));
dx += sw;
if (dx >= this.width ) {
if (!this.repeatX || (dx >= this.width) ) {
// done ("end" of the viewport)
break;
}
Expand Down

0 comments on commit 5a82891

Please sign in to comment.