Compare commits

...

2 Commits

Author SHA1 Message Date
Alexander Popov 1e50ed7a48
draw tiled only by X 2023-04-30 18:59:50 +03:00
Alexander Popov 8ea015eee0
tiled only Y option 2023-04-30 18:54:53 +03:00
2 changed files with 46 additions and 21 deletions

View File

@ -1,6 +1,7 @@
**/.git
**/node_modules
**/dist
test/js/engine.js
*.html
*.css

View File

@ -95,8 +95,10 @@ export class Sprite {
}
export class TiledSprite extends Sprite {
constructor(src = null, x, y) {
constructor(src = null, x, y, only = null) {
super(src, x, y);
this.only = only;
}
draw(context, debug = false) {
@ -126,16 +128,27 @@ export class TiledSprite extends Sprite {
break;
}
context.drawImage(
this.image(),
this.x - this.image().width * ix,
this.y - this.image().height * iy
);
context.drawImage(
this.image(),
this.x + this.image().width * ix,
this.y - this.image().height * iy
);
switch (this.only) {
case 'y':
context.drawImage(this.image(), this.x, this.y - this.image().height * iy);
break;
case 'x':
context.drawImage(this.image(), this.x - this.image().width * ix, this.y);
break;
case null:
default:
context.drawImage(
this.image(),
this.x + this.image().width * ix,
this.y - this.image().height * iy
);
context.drawImage(
this.image(),
this.x - this.image().width * ix,
this.y - this.image().height * iy
);
break;
}
}
}
@ -149,16 +162,27 @@ export class TiledSprite extends Sprite {
break;
}
context.drawImage(
this.image(),
this.x - this.image().width * ix,
this.y + this.image().height * iy
);
context.drawImage(
this.image(),
this.x + this.image().width * ix,
this.y + this.image().height * iy
);
switch (this.only) {
case 'y':
context.drawImage(this.image(), this.x, this.y + this.image().height * iy);
break;
case 'x':
context.drawImage(this.image(), this.x + this.image().width * ix, this.y);
break;
case null:
default:
context.drawImage(
this.image(),
this.x + this.image().width * ix,
this.y + this.image().height * iy
);
context.drawImage(
this.image(),
this.x - this.image().width * ix,
this.y + this.image().height * iy
);
break;
}
}
}
}